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
Validate the given `DateComponents` values up front to align with the supported Calendar calculation date range, defined as `Date.validCalendarRange`.
We could alternatively guard all arithmetic operations with `...reportingOverflow`, but there are too many operations, and so it seems untenable. I opted for a more realistic approach instead. `_CalendarICU` unconditionally truncates values to `Int32`, so the results for `Calendar.date(from:)` have always been incorrect for distant dates anyways.
Fixed 129782208
// `Date.validCalendarRange` supports approximately from year -4713 to year 506713. These valid ranges were chosen as if representing the entire supported date range in one calendar unit.
1591
+
letvalidEra=-10...10
1592
+
letvalidYear=-4714...506714
1593
+
letvalidQuarter=-4714*4...506714*4
1594
+
letvalidWeek=-4714*52...506714*52
1595
+
letvalidWeekday=-4714*52*7...506714*52*7
1596
+
letvalidMonth=-4714*12...506714*12
1597
+
letvalidDayOfYear=-4714*365...506714*365
1598
+
letvalidDayOfMonth=-4714*12*31...506714*12*31
1599
+
letvalidHour=-4714*8760...Int(Int32.max)
1600
+
letvalidMinute=Int(Int32.min)...Int(Int32.max)
1601
+
letvalidSecond=Int(Int32.min)...Int(Int32.max)
1602
+
1603
+
iflet value = components.era {guard validEra.contains(value)else{returnfalse}}
1604
+
iflet value = components.year {guard validYear.contains(value)else{returnfalse}}
1605
+
iflet value = components.quarter {guard validQuarter.contains(value)else{returnfalse}}
1606
+
iflet value = components.weekOfYear {guard validWeek.contains(value)else{returnfalse}}
1607
+
iflet value = components.weekOfMonth {guard validWeek.contains(value)else{returnfalse}}
1608
+
iflet value = components.yearForWeekOfYear {guard validYear.contains(value)else{returnfalse}}
1609
+
iflet value = components.weekday {guard validWeekday.contains(value)else{returnfalse}}
1610
+
iflet value = components.weekdayOrdinal {guard validWeek.contains(value)else{returnfalse}}
1611
+
iflet value = components.month {guard validMonth.contains(value)else{returnfalse}}
1612
+
iflet value = components.dayOfYear {guard validDayOfYear.contains(value)else{returnfalse}}
1613
+
iflet value = components.day {guard validDayOfMonth.contains(value)else{returnfalse}}
1614
+
iflet value = components.hour {guard validHour.contains(value)else{returnfalse}}
1615
+
iflet value = components.minute {guard validMinute.contains(value)else{returnfalse}}
1616
+
iflet value = components.second {guard validSecond.contains(value)else{returnfalse}}
// One or more values exceeds supported date range
1624
+
returnnil
1625
+
}
1626
+
1590
1627
// If the components specifies a new time zone, perform this calculation using the specified timezone
1591
1628
// If the date falls into the skipped time frame when transitioning into DST (e.g. 1:00 - 3:00 AM for PDT), we want to treat it as if DST hasn't happened yet. So, use .former for dstRepeatedTimePolicy.
1592
1629
// If the date falls into the repeated time frame when DST ends (e.g. 1:00 - 2:00 AM for PDT), we want the first instance, i.e. the instance before turning back the clock. So, use .former for dstSkippedTimePolicy.
0 commit comments