Does DateComponents conversion persist across TimeZone shifts?
0 reputation · 01 Sept 2022, 17:29 UTC
When using the Foundation framework, a Date object represents a fixed point in time independent of regional settings. However, when converting this date into DateComponents using a Calendar, the result depends entirely on the TimeZone assigned to that calendar instance.
There is uncertainty regarding the behavior of edge cases near the midnight boundary during Daylight Saving Time (DST) transitions. If a Date is converted to components in a zone with an offset and then re-converted in a different zone with a different DST rule, the resulting 'day' component may shift even if the absolute point in time remains the same.
How specifically does the Calendar.dateComponents(_:in:) method handle transitions when the target TimeZone is changed mid-calculation? Is there a reliable way to ensure the 'day' component remains consistent across multiple regional identifiers without manual offset arithmetic?