diff --git a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt index 48f23686..bf54f83d 100644 --- a/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt +++ b/common/src/commonMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt @@ -10,4 +10,6 @@ expect class DateFormatter constructor(pattern: String) { fun format(date: Date): String + fun parse(dateString: String): Date? + } \ No newline at end of file diff --git a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt index a7ab0d89..103c7d3b 100644 --- a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt +++ b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt @@ -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 + } + } \ No newline at end of file diff --git a/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt index 0985663a..304537f4 100644 --- a/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt +++ b/common/src/jvmMain/kotlin/net/dankito/utils/multiplatform/DateFormatter.kt @@ -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 + } + } \ No newline at end of file