Open markst opened 4 years ago
I think this is the same: https://github.com/malcommac/SwiftDate/issues/775
If I set the region to current:
SwiftDate.defaultRegion = .current
The DateInRegion
behaves more how I expected:
(lldb) po DateInRegion("2020-08-26T17:00:00+10:00")?.region
▿ Optional<Region>
▿ some : {calendar='gregorian', timezone='Australia/Darwin', locale='en_US'}
▿ calendar : gregorian (autoupdatingCurrent)
- identifier : gregorian
- kind : "autoupdatingCurrent"
▿ locale : Optional<Locale>
▿ some : en_US (autoupdatingCurrent)
- identifier : "en_US"
- kind : "autoupdatingCurrent"
▿ timeZone : Australia/Darwin (autoupdatingCurrent)
- identifier : "Australia/Darwin"
- kind : "autoupdatingCurrent"
▿ abbreviation : Optional<String>
- some : "GMT+9:30"
- secondsFromGMT : 34200
- isDaylightSavingTime : false
- firstWeekday : 1
- minimumDaysInFirstWeek : 1
Significant when using DateInRegion.dateComponents
since wrong timezone component is returned.
Just to add; when using toISODate
- the region is preserved:
(lldb) po "2020-08-26T17:00:00+10:00".toISODate()?.region
▿ Optional<Region>
▿ some : {calendar='gregorian', timezone='GMT+1000', locale='en_US_POSIX'}
▿ calendar : gregorian (fixed)
- identifier : gregorian
- kind : "fixed"
▿ locale : Optional<Locale>
▿ some : en_US_POSIX (fixed)
- identifier : "en_US_POSIX"
- kind : "fixed"
▿ timeZone : GMT+1000 (fixed)
- identifier : "GMT+1000"
- kind : "fixed"
▿ abbreviation : Optional<String>
- some : "GMT+10"
- secondsFromGMT : 36000
- isDaylightSavingTime : false
- firstWeekday : 1
- minimumDaysInFirstWeek : 1
I wish to format a date in it's local timezone, however formatting the date will not preserve the region/timezone:
Output: