I am looking to add functionality onto `OffsetDate...
# codingconventions
c
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
You could just make a top level function called
todayAtMidnight()
that just returns what you’re looking for.
Copy code
fun todayAtMidnight() = OffsetDateTime.now().withHour(0).withMinute(0).withSecond(0)
c
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!