Added parse()
This commit is contained in:
parent
cc72d9792e
commit
e59fd7b107
|
@ -10,4 +10,6 @@ expect class DateFormatter constructor(pattern: String) {
|
|||
|
||||
fun format(date: Date): String
|
||||
|
||||
fun parse(dateString: String): Date?
|
||||
|
||||
}
|
|
@ -37,4 +37,12 @@ actual class DateFormatter actual constructor(val pattern: String): NSDateFormat
|
|||
return stringFromDate(date.date)
|
||||
}
|
||||
|
||||
actual fun parse(dateString: String): Date? {
|
||||
super.dateFromString(dateString)?.let { nsDate ->
|
||||
return Date(nsDate)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
|
@ -27,4 +27,12 @@ actual class DateFormatter actual constructor(val pattern: String): SimpleDateFo
|
|||
return super.format(date)
|
||||
}
|
||||
|
||||
actual override fun parse(dateString: String): Date? {
|
||||
super.parse(dateString)?.let { javaDate ->
|
||||
return Date(javaDate.time)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue