All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.krono.internal.AbstractZonedDateTime.kt Maven / Gradle / Ivy

There is a newer version: 3.0.14
Show newest version
package krono.internal

import krono.DateLike
import krono.DayOfWeek
import krono.LocalDate
import krono.LocalDateTime
import krono.LocalTime
import krono.Month
import krono.TimeLike
import krono.TimeZone
import krono.ZonedDateTime
import krono.utils.DaysOfMonth

abstract class AbstractZonedDateTime(
    override val date: LocalDate,
    override val time: LocalTime,
    override val zone: TimeZone
) : AbstractDateLike(), ZonedDateTime, DateLike, TimeLike by time {

    override val year: Int get() = date.year
    override val monthNumber: Int get() = date.monthNumber
    override val month: Month get() = date.month
    override val dayOfMonth: Int get() = date.dayOfMonth
    override val dayOfWeek: DayOfWeek get() = date.dayOfWeek
    override val dayOfYear: Int get() = date.dayOfYear

    private val compareError = """
        [  ERROR  ] Can't compare Dates from different timezones
        [ FIX TIP ] Bring all the dates to UTC and compare them then 
    """.trimIndent()

    override fun compareTo(other: ZonedDateTime): Int {
        if (zone.id != other.zone.id) throw UnsupportedOperationException(compareError)
        return date.compareTo(other.date) + time.compareTo(other.time)
    }

    override fun format(pattern: String): String {
        return super.format(pattern)
    }

    override fun toIsoString(): String {
        return super.toIsoString()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy