Fixed time zone offset which NSCalendar doesn't take into account

This commit is contained in:
dankito 2020-09-21 00:37:24 +02:00
parent a382904015
commit a4a70bbd32
1 changed files with 4 additions and 1 deletions

View File

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