add instant function. Previously using Kotlinx libs now change to java
This commit is contained in:
parent
2fdc9c4f9a
commit
dc877f7da7
@ -2,5 +2,21 @@
|
||||
|
||||
package ai.neuon.utility.time
|
||||
|
||||
import java.time.ZoneId
|
||||
import kotlin.time.ExperimentalTime
|
||||
import kotlin.time.Instant
|
||||
import java.time.Instant as JavaInstant
|
||||
|
||||
fun Instant.atStartOfMonth(timezone: ZoneId): Instant {
|
||||
val javaInstant = JavaInstant.ofEpochSecond(epochSeconds, nanosecondsOfSecond.toLong())
|
||||
val zoned = javaInstant.atZone(timezone)
|
||||
.withDayOfMonth(1)
|
||||
.withHour(0).withMinute(0).withSecond(0).withNano(0)
|
||||
return Instant.fromEpochSeconds(zoned.toEpochSecond(), zoned.nano)
|
||||
}
|
||||
|
||||
fun Instant.plusMonths(months: Long, timezone: ZoneId): Instant {
|
||||
val javaInstant = JavaInstant.ofEpochSecond(epochSeconds, nanosecondsOfSecond.toLong())
|
||||
val zoned = javaInstant.atZone(timezone).plusMonths(months)
|
||||
return Instant.fromEpochSeconds(zoned.toEpochSecond(), zoned.nano)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user