Added parse()

This commit is contained in:
dankito 2020-07-12 11:11:16 +02:00
parent cc72d9792e
commit e59fd7b107
3 changed files with 18 additions and 0 deletions

View File

@ -10,4 +10,6 @@ expect class DateFormatter constructor(pattern: String) {
fun format(date: Date): String
fun parse(dateString: String): Date?
}

View File

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

View File

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