https://kotlinlang.org logo
Title
c

Cody Engel

04/18/2019, 3:34 PM
I am looking to add functionality onto
OffsetDateTime
where I’d be able to do something like
OffsetDateTime.todayAtMidnight
to get the time for today at midnight. If I could do an extension static function on that class then my problem would be solved but alas I don’t think you can do that. Would the best option be to just use the factory pattern and have a
OffsetDateTimeFactory
that’s just a collection of ways to create
OffsetDateTime
instances for specific cases?
r

rook

04/18/2019, 3:56 PM
You could just make a top level function called
todayAtMidnight()
that just returns what you’re looking for.
fun todayAtMidnight() = OffsetDateTime.now().withHour(0).withMinute(0).withSecond(0)
c

Cody Engel

04/18/2019, 5:49 PM
Oof, I seem to forget about top level functions. That seems like another good option, I’ll check with my team to see which they prefer, thank you!