From 83880c7b2410825d26849ed24f10ddfc96d7522e Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 12 Jul 2020 00:45:57 +0200 Subject: [PATCH] Fixed that deriving from NSDate is not (that easily) possible as NSDate is a class cluster --- .../iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt | 7 ++++--- .../net/dankito/utils/multiplatform/DateFormatter.kt | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt index 41810fd9..e74201a3 100644 --- a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt +++ b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt @@ -8,18 +8,19 @@ fun NSTimeInterval.toMillis(): Long { } -actual class Date actual constructor(millisSinceEpoch: Long) - : NSDate(timeIntervalSinceReferenceDate = ((millisSinceEpoch - DiffBetweenEpochTimeAndReferenceDate) / 1000).toDouble()) { // TODO: does this work? +actual class Date(val date: NSDate) { // cannot subclass NSDate as it's a class cluster companion object { val DiffBetweenEpochTimeAndReferenceDate = (NSDate.timeIntervalSinceReferenceDate - NSTimeIntervalSince1970).toMillis() } + actual constructor(millisSinceEpoch: Long) : this(NSDate(timeIntervalSinceReferenceDate = ((millisSinceEpoch - DiffBetweenEpochTimeAndReferenceDate) / 1000).toDouble())) + actual constructor() : this(NSDate().timeIntervalSince1970.toMillis()) actual val millisSinceEpoch: Long - get() = timeIntervalSince1970.toMillis() + get() = date.timeIntervalSince1970.toMillis() } \ No newline at end of file diff --git a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt index 251431f9..a7ab0d89 100644 --- a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt +++ b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt @@ -34,7 +34,7 @@ actual class DateFormatter actual constructor(val pattern: String): NSDateFormat actual fun format(date: Date): String { - return stringFromDate(date) + return stringFromDate(date.date) } } \ No newline at end of file