You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TimeZone, Calendar, and Locale disagree on how .current is serialized (#1491)
* (157160558) TimeZone, Calendar, and Locale disagree on how .current is encoded
* Revert roundtripEncoding back to its original state
* Address feedback
iflet current =try container.decodeIfPresent(Current.self, forKey:.current){
1620
-
switch current {
1621
-
case.autoupdatingCurrent:
1622
-
self=Calendar.autoupdatingCurrent
1623
-
return
1624
-
case.current:
1625
-
self=Calendar.current
1626
-
return
1627
-
case.fixed:
1628
-
// Fall through to identifier-based
1629
-
break
1630
-
}
1619
+
iflet current =try container.decodeIfPresent(Current.self, forKey:.current), current ==.autoupdatingCurrent {
1620
+
self=Calendar.autoupdatingCurrent
1621
+
return
1631
1622
}
1623
+
1624
+
// Just like TimeZone and Locale, Whether the calendar was fixed or current we decode as a fixed calendar if it wasn't encoded as the sentinel autoupdating current
// current and autoupdatingCurrent are sentinel values. Calendar could theoretically not treat 'current' as a sentinel, but it is required for Locale (one of the properties of Calendar), so transitively we have to do the same here
1651
+
// autoupdatingCurrent is a sentinel value
1652
+
// Prior to FoundationPreview 6.3 releases, Calendar treated current-equivalent calendars as sentinel values while decoding as well. As of FoundationPreview 6.2 releases, Calendar no longer decodes the current sentinel value, but it is still encoded to preserve behavior when decoding with older runtimes
iflet current =try container.decodeIfPresent(Current.self, forKey:.current){
830
836
switch current {
831
837
case.autoupdatingCurrent:
832
838
self=Locale.autoupdatingCurrent
833
839
return
834
840
case.current:
835
-
self=Locale.current
836
-
return
841
+
if prefs ==nil{
842
+
// Prior to FoundationPreview 6.3 releases, Locale did not encode preferences and expected decoding .current to decode with the new current user's preferences via the new process' .currrent locale
843
+
// Preserve behavior for encoded current locales without encoded preferences by decoding as the current locale here to preserve the intent of including user preferences even though preferences are not included in the archive
844
+
// If preferences were encoded (the current locale encoded from a post-FoundationPreview 6.3 release), fallthrough to the new behavior below
// Always encode .current for the current locale to preserve existing decoding behavior of .current when decoding on older runtimes prior to FoundationPreview 6.3 releases
// Encode preferences (if present) so that when decoding on newer runtimes (FoundationPreview 6.3 releases and later) we create a locale with the preferences as they are at encode time
/// Holds user preferences about `Locale`, retrieved from user defaults. It is only used when creating the `current` Locale. Fixed-identifier locales never have preferences.
// The following `CFDictionary` ivars are used directly by `CFDateFormatter`. Keep them as `CFDictionary` to avoid bridging them into and out of Swift. We don't need to access them from Swift at all.
// Autoupdating current timezones are treated as sentinel values, but the current TimeZone is encoded as a fixed TimeZone
340
+
// This is the same behavior as Locale/Calendar except it did not previously encode as a sentinel value before FoundationPreview 6.3, so no extra key is encoded for the current time zone
/// Reads from environment variables `TZFILE`, `TZ` and finally the symlink pointed at by the C macro `TZDEFAULT` to figure out what the current (aka "system") time zone is.
0 commit comments