From e59fd7b1074cf25db8e168a084d9bdd0eb09dfee Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 12 Jul 2020 11:11:16 +0200 Subject: [PATCH] Added parse() --- .../net/dankito/utils/multiplatform/DateFormatter.kt | 2 ++ .../net/dankito/utils/multiplatform/DateFormatter.kt | 8 ++++++++ .../net/dankito/utils/multiplatform/DateFormatter.kt | 8 ++++++++ 3 files changed, 18 insertions(+) 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