commonMain.LocalDateTimeMath.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of time-jvm Show documentation
Show all versions of time-jvm Show documentation
A collection of drawing/charting utilities
The newest version!
package com.juul.krayon.time
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone.Companion.UTC
import kotlinx.datetime.toInstant
import kotlinx.datetime.toLocalDateTime
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
@OptIn(ExperimentalTime::class)
public operator fun LocalDateTime.plus(duration: Duration): LocalDateTime =
(this.toInstant(UTC) + duration).toLocalDateTime(UTC)
@OptIn(ExperimentalTime::class)
public operator fun LocalDateTime.minus(duration: Duration): LocalDateTime =
(this.toInstant(UTC) - duration).toLocalDateTime(UTC)
@OptIn(ExperimentalTime::class)
public operator fun LocalDateTime.minus(other: LocalDateTime): Duration =
this.toInstant(UTC) - other.toInstant(UTC)