From 10cb1152a2cb76609e6f65a0e7a2690013d3de16 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Tue, 12 Apr 2022 00:24:14 -0500 Subject: Initial version of custom reports in iOS --- .../mx/trackermap/TrackerMap/utils/DateUtils.kt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/utils/DateUtils.kt (limited to 'shared/src/iosMain/kotlin') diff --git a/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/utils/DateUtils.kt b/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/utils/DateUtils.kt new file mode 100644 index 0000000..7286ea5 --- /dev/null +++ b/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/utils/DateUtils.kt @@ -0,0 +1,22 @@ +package mx.trackermap.TrackerMap.utils + +import kotlinx.datetime.* +import platform.Foundation.NSDate +import platform.Foundation.NSDateFormatter + +actual class DateUtils { + actual companion object { + fun iosDateToKotlin(date: NSDate): LocalDateTime { + val timezone = TimeZone.currentSystemDefault() + return date.toKotlinInstant().toLocalDateTime(timezone) + } + + actual fun formatDate(date: LocalDateTime): String { + val timezone = TimeZone.currentSystemDefault() + val iosDate = date.toInstant(timezone).toNSDate() + val formatter = NSDateFormatter() + formatter.setDateFormat("yyyy-MM-dd HH:mm") + return formatter.stringFromDate(iosDate) + } + } +} \ No newline at end of file -- cgit v1.2.3