TimeZone, Calendar, and Locale disagree on how .current
is serialized
#1491
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There's been a handful of changes over the years in this area, but the situation we have today is that
TimeZone
,Calendar
, andLocale
all have different behaviors for how they encode.current
. All 3 mostly agree that.autoupdatingCurrent
is always encoded as as sentinel value becoming the.autoupdatingCurrent
at decode time, and that fixed values are decoded simply as fixed values (Calendar doesn't do the latter sometimes). However:TimeZone
always encodes.current
as a fixed value. When decoded it is the same time zone that was encoded regardless of.current
at decode timeLocale
always encodes.current
as a sentinel value. When decoded, it takes the value of whatever.current
is at decode time regardless of the locale that was encodedCalendar
encodes a sentinel current value if the calendar to be encoded is equivalent to the current locale (i.e. if it has the same identifier/properties). This means that.current
is always encoded as a sentinel value likeLocale
, but some fixed values are also encoded as a.current
sentinelThe desired behavior is what
TimeZone
does today -.current
represents a snapshot in time and we should encode that fixed snapshot unless.autoupdatingCurrent
is used (in which case it should update at decode time). This is trickier forLocale
becauseLocale
contains extra user preferences that are persisted neither in the identifier nor other archive keys (which is why it is not its behavior today). This means encodingLocale.current
as a fixed locale with just an identifier results in lost information due to lost preferences.To fix this we do two things:
Locale
now persists preferences in the archive (when present) alongside the identifier (to prevent data loss) and.current
is no longer decoded as a sentinel to matchTimeZone
Calendar
no longer decodes.current
as a sentinel value to matchTimeZone
(and nowLocale
)With this change, we always decode a
Calendar
that was encoded as.current
as a fixed Calendar based on the encoded values. We still encode the.current
key to preserve the preexisting behavior when decoding on an older runtime, but newer runtimes will ignore the.current
sentinel and decode the various keys.This also adds unit tests to each type that validates consistent behavior for all 3 types.