Fixed that deriving from NSDate is not (that easily) possible as NSDate is a class cluster
This commit is contained in:
parent
956116bd9f
commit
83880c7b24
|
@ -8,18 +8,19 @@ fun NSTimeInterval.toMillis(): Long {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
actual class Date actual constructor(millisSinceEpoch: Long)
|
actual class Date(val date: NSDate) { // cannot subclass NSDate as it's a class cluster
|
||||||
: NSDate(timeIntervalSinceReferenceDate = ((millisSinceEpoch - DiffBetweenEpochTimeAndReferenceDate) / 1000).toDouble()) { // TODO: does this work?
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val DiffBetweenEpochTimeAndReferenceDate = (NSDate.timeIntervalSinceReferenceDate - NSTimeIntervalSince1970).toMillis()
|
val DiffBetweenEpochTimeAndReferenceDate = (NSDate.timeIntervalSinceReferenceDate - NSTimeIntervalSince1970).toMillis()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
actual constructor(millisSinceEpoch: Long) : this(NSDate(timeIntervalSinceReferenceDate = ((millisSinceEpoch - DiffBetweenEpochTimeAndReferenceDate) / 1000).toDouble()))
|
||||||
|
|
||||||
actual constructor() : this(NSDate().timeIntervalSince1970.toMillis())
|
actual constructor() : this(NSDate().timeIntervalSince1970.toMillis())
|
||||||
|
|
||||||
|
|
||||||
actual val millisSinceEpoch: Long
|
actual val millisSinceEpoch: Long
|
||||||
get() = timeIntervalSince1970.toMillis()
|
get() = date.timeIntervalSince1970.toMillis()
|
||||||
|
|
||||||
}
|
}
|
|
@ -34,7 +34,7 @@ actual class DateFormatter actual constructor(val pattern: String): NSDateFormat
|
||||||
|
|
||||||
|
|
||||||
actual fun format(date: Date): String {
|
actual fun format(date: Date): String {
|
||||||
return stringFromDate(date)
|
return stringFromDate(date.date)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue