commonMain.io.islandtime.internal.Instants.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core-metadata Show documentation
Show all versions of core-metadata Show documentation
A multiplatform library for working with dates and times
The newest version!
package io.islandtime.internal
import dev.erikchristensen.javamath2kmp.floorDiv
import io.islandtime.*
internal fun toTimeAt(offset: UtcOffset, secondOfUnixEpoch: Long, nanosecond: Int): Time {
val nanosecondOfDay = ((secondOfUnixEpoch % SECONDS_PER_DAY) * NANOSECONDS_PER_SECOND
+ nanosecond + offset.totalSeconds.inNanoseconds.value + NANOSECONDS_PER_DAY) % NANOSECONDS_PER_DAY
return Time.fromNanosecondOfDay(nanosecondOfDay)
}
internal fun toOffsetTimeAt(offset: UtcOffset, secondOfUnixEpoch: Long, nanosecond: Int): OffsetTime {
return toTimeAt(offset, secondOfUnixEpoch, nanosecond) at offset
}
internal fun toDateAt(offset: UtcOffset, secondOfUnixEpoch: Long): Date {
val dayOfUnixEpoch = (secondOfUnixEpoch + offset.totalSeconds.value) floorDiv SECONDS_PER_DAY
return Date.fromDayOfUnixEpoch(dayOfUnixEpoch)
}
internal fun toDateTimeAt(offset: UtcOffset, secondOfUnixEpoch: Long, nanosecond: Int): DateTime {
return DateTime.fromSecondOfUnixEpoch(secondOfUnixEpoch, nanosecond, offset)
}
internal fun toOffsetDateTimeAt(offset: UtcOffset, secondOfUnixEpoch: Long, nanosecond: Int): OffsetDateTime {
return OffsetDateTime.fromSecondOfUnixEpoch(secondOfUnixEpoch, nanosecond, offset)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy