From a4a70bbd32b5767030698f693f8b72ab67c58bf8 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 21 Sep 2020 00:37:24 +0200 Subject: [PATCH] Fixed time zone offset which NSCalendar doesn't take into account --- .../iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt index 73a332c6..3ca108c2 100644 --- a/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt +++ b/common/src/iosMain/kotlin/net/dankito/utils/multiplatform/Date.kt @@ -29,7 +29,10 @@ actual class Date(val date: NSDate) { // cannot subclass NSDate as it's a class dateComponents.month = month.toLong() dateComponents.day = day.toLong() - return NSCalendar.currentCalendar.dateFromComponents(dateComponents) !! + val calendar = NSCalendar.currentCalendar + val todayInUtc = calendar.dateFromComponents(dateComponents) !! + + return calendar.dateByAddingUnit(NSCalendarUnitSecond, NSTimeZone.defaultTimeZone.secondsFromGMT, todayInUtc, 0)!! }