diff --git a/multiplatform-utils/src/commonMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt b/multiplatform-utils/src/commonMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt index b9459c72..3c9e116e 100644 --- a/multiplatform-utils/src/commonMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt +++ b/multiplatform-utils/src/commonMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt @@ -15,7 +15,8 @@ expect class DateFormatter constructor(pattern: String) { fun format(date: LocalDateTime): String - fun format(date: LocalDate): String + // cannot be named format() due to JavaScript name conflicts + fun formatDate(date: LocalDate): String fun parseDate(dateString: String): LocalDate? diff --git a/multiplatform-utils/src/commonMain/kotlin/net/dankito/utils/multiplatform/extensions/LocalDateExtensions.kt b/multiplatform-utils/src/commonMain/kotlin/net/dankito/utils/multiplatform/extensions/LocalDateExtensions.kt index a5e17015..0523028a 100644 --- a/multiplatform-utils/src/commonMain/kotlin/net/dankito/utils/multiplatform/extensions/LocalDateExtensions.kt +++ b/multiplatform-utils/src/commonMain/kotlin/net/dankito/utils/multiplatform/extensions/LocalDateExtensions.kt @@ -2,23 +2,28 @@ package net.dankito.utils.multiplatform.extensions import kotlinx.datetime.* import net.dankito.utils.multiplatform.DateFormatter +import kotlin.js.JsName val LocalDate.Companion.atUnixEpochStart: LocalDate get() = fromEpochMillisecondsAtUtc(0) +@JsName("dateFromEpochMillisecondsAtUtc") fun LocalDate.Companion.fromEpochMillisecondsAtUtc(epochMilliseconds: Long): LocalDate { return fromEpochMilliseconds(epochMilliseconds, TimeZone.UTC) } +@JsName("dateFromEpochMillisecondsAtSystemDefaultTimeZone") fun LocalDate.Companion.fromEpochMillisecondsAtSystemDefaultTimeZone(epochMilliseconds: Long): LocalDate { return fromEpochMilliseconds(epochMilliseconds, TimeZone.currentSystemDefault()) } +@JsName("dateFromEpochMillisecondsAtEuropeBerlin") fun LocalDate.Companion.fromEpochMillisecondsAtEuropeBerlin(epochMilliseconds: Long): LocalDate { return fromEpochMilliseconds(epochMilliseconds, TimeZone.europeBerlin) } +@JsName("dateFromEpochMilliseconds") fun LocalDate.Companion.fromEpochMilliseconds(epochMilliseconds: Long, timeZone: TimeZone): LocalDate { return Instant.fromEpochMilliseconds(epochMilliseconds).toLocalDateTime(timeZone).date } @@ -36,24 +41,27 @@ fun LocalDate.Companion.todayAtEuropeBerlin(): LocalDate { return nowAt(TimeZone.europeBerlin) } +@JsName("nowAtForTimeZoneStringForDate") fun LocalDate.Companion.nowAt(timeZone: String): LocalDate { return nowAt(TimeZone.of(timeZone)) } +@JsName("nowAtForDate") fun LocalDate.Companion.nowAt(timeZone: TimeZone): LocalDate { return Clock.System.todayAt(timeZone) } -val LocalDate.millisSinceEpochAtUtc: Long - get() = this.toEpochMillisecondsAt(TimeZone.UTC) - -val LocalDate.millisSinceEpochAtSystemDefaultTimeZone: Long - get() = this.toEpochMillisecondsAt(TimeZone.currentSystemDefault()) +//val LocalDate.millisSinceEpochAtUtc: Long +// get() = this.toEpochMillisecondsAt(TimeZone.UTC) +// +//val LocalDate.millisSinceEpochAtSystemDefaultTimeZone: Long +// get() = this.toEpochMillisecondsAt(TimeZone.currentSystemDefault()) val LocalDate.millisSinceEpochAtEuropeBerlin: Long get() = this.toEpochMillisecondsAt(TimeZone.europeBerlin) +@JsName("toEpochMillisecondsAtForDate") fun LocalDate.toEpochMillisecondsAt(timeZone: TimeZone): Long { return this.toLocalDateTime().toInstant(timeZone).toEpochMilliseconds() } @@ -72,10 +80,12 @@ fun LocalDate.minusDays(days: Int): LocalDate { } +@JsName("formatDate") fun LocalDate.format(formatter: DateFormatter): String { return this.atTime(0, 0).format(formatter) } +@JsName("formatDatePattern") fun LocalDate.format(pattern: String): String { return this.format(DateFormatter(pattern)) } \ No newline at end of file diff --git a/multiplatform-utils/src/commonMain/kotlin/net/dankito/utils/multiplatform/extensions/LocalDateTimeExtensions.kt b/multiplatform-utils/src/commonMain/kotlin/net/dankito/utils/multiplatform/extensions/LocalDateTimeExtensions.kt index e1cf284b..dc3d9df0 100644 --- a/multiplatform-utils/src/commonMain/kotlin/net/dankito/utils/multiplatform/extensions/LocalDateTimeExtensions.kt +++ b/multiplatform-utils/src/commonMain/kotlin/net/dankito/utils/multiplatform/extensions/LocalDateTimeExtensions.kt @@ -2,6 +2,7 @@ package net.dankito.utils.multiplatform.extensions import kotlinx.datetime.* import net.dankito.utils.multiplatform.DateFormatter +import kotlin.js.JsName fun LocalDateTime.Companion.of(hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0): LocalDateTime { @@ -37,6 +38,7 @@ fun LocalDateTime.Companion.nowAtEuropeBerlin(): LocalDateTime { return nowAt(TimeZone.europeBerlin) } +@JsName("nowAtForTimeZoneString") fun LocalDateTime.Companion.nowAt(timeZone: String): LocalDateTime { return nowAt(TimeZone.of(timeZone)) } @@ -52,8 +54,8 @@ val LocalDateTime.millisSinceEpochAtUtc: Long val LocalDateTime.millisSinceEpochAtSystemDefaultTimeZone: Long get() = this.toEpochMillisecondsAt(TimeZone.currentSystemDefault()) -val LocalDateTime.millisSinceEpochAtEuropeBerlin: Long - get() = this.toEpochMillisecondsAt(TimeZone.europeBerlin) +//val LocalDateTime.millisSinceEpochAtEuropeBerlin: Long +// get() = this.toEpochMillisecondsAt(TimeZone.europeBerlin) fun LocalDateTime.toEpochMillisecondsAt(timeZone: TimeZone): Long { return this.toInstant(timeZone).toEpochMilliseconds() @@ -64,6 +66,7 @@ fun LocalDateTime.format(formatter: DateFormatter): String { return formatter.format(this) } +@JsName("formatPattern") fun LocalDateTime.format(pattern: String): String { return this.format(DateFormatter(pattern)) } \ No newline at end of file diff --git a/multiplatform-utils/src/iosMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt b/multiplatform-utils/src/iosMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt index 3bacf2f8..2470baaa 100644 --- a/multiplatform-utils/src/iosMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt +++ b/multiplatform-utils/src/iosMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt @@ -36,7 +36,7 @@ actual class DateFormatter actual constructor(val pattern: String): NSDateFormat } - actual fun format(date: LocalDate): String { + actual fun formatDate(date: LocalDate): String { return format(date.toLocalDateTime()) } diff --git a/multiplatform-utils/src/jsMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt b/multiplatform-utils/src/jsMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt index 756250a6..a0f00e83 100644 --- a/multiplatform-utils/src/jsMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt +++ b/multiplatform-utils/src/jsMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt @@ -11,7 +11,7 @@ actual class DateFormatter actual constructor(pattern: String) { actual constructor(dateStyle: DateFormatStyle, timeStyle: DateFormatStyle) : this("") - actual fun format(date: LocalDate): String { + actual fun formatDate(date: LocalDate): String { return format(date.toLocalDateTime()) } diff --git a/multiplatform-utils/src/jvmMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt b/multiplatform-utils/src/jvmMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt index 6308b066..10c5278a 100644 --- a/multiplatform-utils/src/jvmMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt +++ b/multiplatform-utils/src/jvmMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt @@ -29,7 +29,7 @@ actual class DateFormatter actual constructor(pattern: String) { : this((DateFormat.getDateTimeInstance(dateStyle.convert(), timeStyle.convert()) as? SimpleDateFormat)?.toPattern() ?: "") - actual fun format(date: LocalDate): String { + actual fun formatDate(date: LocalDate): String { return format(date.toLocalDateTime()) } diff --git a/multiplatform-utils/src/nativeMain/kotlin/net.dankito.utils.multiplatform/DateFormatter.kt b/multiplatform-utils/src/nativeMain/kotlin/net.dankito.utils.multiplatform/DateFormatter.kt index 14a13032..c6342723 100644 --- a/multiplatform-utils/src/nativeMain/kotlin/net.dankito.utils.multiplatform/DateFormatter.kt +++ b/multiplatform-utils/src/nativeMain/kotlin/net.dankito.utils.multiplatform/DateFormatter.kt @@ -11,7 +11,7 @@ actual class DateFormatter actual constructor(pattern: String) { actual constructor(dateStyle: DateFormatStyle, timeStyle: DateFormatStyle) : this("") - actual fun format(date: LocalDate): String { + actual fun formatDate(date: LocalDate): String { return format(date.toLocalDateTime()) }