Fixed that deriving from NSDate is not (that easily) possible as NSDate is a class cluster

This commit is contained in:
dankito 2020-07-12 00:45:57 +02:00
parent 956116bd9f
commit 83880c7b24
2 changed files with 5 additions and 4 deletions

View File

@ -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()
}

View File

@ -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)
}
}