Is there any notion of rounding an `Instant` or `L...
# kotlinx-datetime
k
Is there any notion of rounding an
Instant
or
LocalDateTime
to a specific
DateTimeUnit
? Is that a reasonable thing to want? I might be reaching for the wrong thing right now.
Some context: I'm trying to implement a scheduler like thing that can execute a certain task at the beginning of a (second|minute|hour|day|week|months|year) in a given time zone. My approach to this is
delay
based, so I need to work out the amount of time between
now
and the beginning of a day, week, month, quarter, etc.
Some example schedules might be 1. Execute a task at the beginning of every (second, minute, hour) 2. Execute a task every 12 hours aligned to midnight and noon in a given time zone 3. Execute a task every calendar day at midnight in a specific time zone
a
‘rounding’ time is also called ‘truncating’, which might help you find a workaround: • https://kotlinlang.slack.com/archives/C01923PC6A0/p1683729951821599https://github.com/Kotlin/kotlinx-datetime/issues/235
k
Oh yeah this is great. Thanks for the tip!
👍 1
212 Views