Implemented DateFormatter for iOS
This commit is contained in:
parent
2a301c9975
commit
ee9c05e518
|
@ -1,7 +1,6 @@
|
||||||
package net.dankito.utils.multiplatform
|
package net.dankito.utils.multiplatform
|
||||||
|
|
||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.*
|
||||||
import kotlinx.datetime.LocalDateTime
|
|
||||||
import platform.Foundation.*
|
import platform.Foundation.*
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,20 +35,19 @@ actual class DateFormatter actual constructor(val pattern: String): NSDateFormat
|
||||||
|
|
||||||
|
|
||||||
actual fun format(date: LocalDateTime): String {
|
actual fun format(date: LocalDateTime): String {
|
||||||
return stringFromDate(date) // TODO: convert to NSDate when back on Mac
|
val instant = date.toInstant(TimeZone.currentSystemDefault())
|
||||||
|
val nsDate = instant.toNSDate()
|
||||||
|
|
||||||
|
return this.stringFromDate(nsDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun parseDate(dateString: String): LocalDate? {
|
actual fun parseDate(dateString: String): LocalDate? {
|
||||||
super.dateFromString(dateString)?.let { nsDate ->
|
return parse(dateString)?.date
|
||||||
return LocalDate(nsDate) // TODO: convert to NSDate when back on Mac
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun parse(dateString: String): LocalDateTime? {
|
actual fun parse(dateString: String): LocalDateTime? {
|
||||||
super.dateFromString(dateString)?.let { nsDate ->
|
this.dateFromString(dateString)?.let { nsDate ->
|
||||||
return LocalDateTime(nsDate) // TODO: convert to NSDate when back on Mac
|
return nsDate.toKotlinInstant().toLocalDateTime(TimeZone.currentSystemDefault())
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
|
Loading…
Reference in New Issue