|
| 1 | +From 9853dabe6e46fb641e888fa3fb6149d2ef712640 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Manish Goregaokar <manishsmail@gmail.com> |
| 3 | +Date: Thu, 28 May 2026 19:54:27 +0000 |
| 4 | +Subject: [PATCH] agent-driven: fix(zoned_date_time): clamp thisNs to endNs - 1 |
| 5 | + in ZonedDateTime.round when smallestUnit is Day |
| 6 | + |
| 7 | +--- |
| 8 | + third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_2/src/builtins/core/zoned_date_time.rs | 17 ++-- |
| 9 | + third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_2/src/builtins/core/zoned_date_time/tests.rs | 101 +++++++++++++++++++++ |
| 10 | + 2 files changed, 111 insertions(+), 7 deletions(-) |
| 11 | + |
| 12 | +diff --git a/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_2/src/builtins/core/zoned_date_time.rs b/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_2/src/builtins/core/zoned_date_time.rs |
| 13 | +index ff4e320..a5b1199 100644 |
| 14 | +--- a/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_2/src/builtins/core/zoned_date_time.rs |
| 15 | ++++ b/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_2/src/builtins/core/zoned_date_time.rs |
| 16 | +@@ -1301,17 +1301,20 @@ impl ZonedDateTime { |
| 17 | + // c. Let startNs be ? GetStartOfDay(timeZone, dateStart). |
| 18 | + // d. Assert: thisNs ≥ startNs. |
| 19 | + // e. Let endNs be ? GetStartOfDay(timeZone, dateEnd). |
| 20 | +- // f. Assert: thisNs < endNs. |
| 21 | ++ // f. [Struck out in spec] Assert: thisNs < endNs. |
| 22 | + let start = self.time_zone.get_start_of_day(&iso_start.date, provider)?; |
| 23 | + let end = self.time_zone.get_start_of_day(&iso_end, provider)?; |
| 24 | +- if !(this_ns.0 >= start.ns.0 && this_ns.0 < end.ns.0) { |
| 25 | ++ if this_ns.0 < start.ns.0 { |
| 26 | + return Err(TemporalError::range().with_enum(ErrorMessage::ZDTOutOfDayBounds)); |
| 27 | + } |
| 28 | +- // g. Let dayLengthNs be ℝ(endNs - startNs). |
| 29 | +- // h. Let dayProgressNs be TimeDurationFromEpochNanosecondsDifference(thisNs, startNs). |
| 30 | ++ // g. Set thisNs to min(thisNs, endNs - 1). |
| 31 | ++ let this_ns_val = this_ns.0.min(end.ns.0 - 1); |
| 32 | ++ // h. Let dayLengthNs be ℝ(endNs - startNs). |
| 33 | ++ // i. Let dayProgressNs be TimeDurationFromEpochNanosecondsDifference(thisNs, startNs). |
| 34 | + let day_len_ns = TimeDuration::from_nanosecond_difference(end.ns.0, start.ns.0)?; |
| 35 | +- let day_progress_ns = TimeDuration::from_nanosecond_difference(this_ns.0, start.ns.0)?; |
| 36 | +- // i. Let roundedDayNs be ! RoundTimeDurationToIncrement(dayProgressNs, dayLengthNs, roundingMode). |
| 37 | ++ let day_progress_ns = |
| 38 | ++ TimeDuration::from_nanosecond_difference(this_ns_val, start.ns.0)?; |
| 39 | ++ // j. Let roundedDayNs be ! RoundTimeDurationToIncrement(dayProgressNs, dayLengthNs, roundingMode). |
| 40 | + let rounded = if let Some(increment) = NonZeroU128::new(day_len_ns.0.unsigned_abs()) { |
| 41 | + IncrementRounder::<i128>::from_signed_num(day_progress_ns.0, increment)? |
| 42 | + .round(resolved.rounding_mode) |
| 43 | +@@ -1326,7 +1329,7 @@ impl ZonedDateTime { |
| 44 | + end.offset |
| 45 | + }; |
| 46 | + |
| 47 | +- // j. Let epochNanoseconds be AddTimeDurationToEpochNanoseconds(roundedDayNs, startNs). |
| 48 | ++ // k. Let epochNanoseconds be AddTimeDurationToEpochNanoseconds(roundedDayNs, startNs). |
| 49 | + let candidate = start.ns.0 + rounded; |
| 50 | + Instant::try_new(candidate)?; |
| 51 | + // 20. Return ! CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar). |
| 52 | +diff --git a/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_2/src/builtins/core/zoned_date_time/tests.rs b/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_2/src/builtins/core/zoned_date_time/tests.rs |
| 53 | +index e56df72..0efc542 100644 |
| 54 | +--- a/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_2/src/builtins/core/zoned_date_time/tests.rs |
| 55 | ++++ b/third_party/rust/chromium_crates_io/vendor/temporal_rs-v0_2/src/builtins/core/zoned_date_time/tests.rs |
| 56 | +@@ -1278,3 +1278,104 @@ fn hours_in_day_dst_changes() { |
| 57 | + assert_eq!(spring.hours_in_day_with_provider(provider), Ok(23.0)); |
| 58 | + }) |
| 59 | + } |
| 60 | ++ |
| 61 | ++// Case where midnight occurs twice (e.g., Antarctica/Casey on 2010-03-05). |
| 62 | ++// Upstream tests: https://github.com/tc39/test262/pull/5047 |
| 63 | ++#[test] |
| 64 | ++fn test_same_date_starts_twice() { |
| 65 | ++ test_all_providers!(provider: { |
| 66 | ++ let zdt1 = ZonedDateTime::from_utf8_with_provider( |
| 67 | ++ b"2010-03-04T23:10:00+11:00[Antarctica/Casey]", |
| 68 | ++ Disambiguation::Compatible, |
| 69 | ++ OffsetDisambiguation::Use, |
| 70 | ++ provider, |
| 71 | ++ ); |
| 72 | ++ if zdt1.is_err() { |
| 73 | ++ std::println!("Antarctica/Casey not supported by provider, skipping test."); |
| 74 | ++ return; |
| 75 | ++ } |
| 76 | ++ let zdt1 = zdt1.unwrap(); |
| 77 | ++ |
| 78 | ++ let zdt2 = ZonedDateTime::from_utf8_with_provider( |
| 79 | ++ b"2010-03-05T00:45:00+11:00[Antarctica/Casey]", |
| 80 | ++ Disambiguation::Compatible, |
| 81 | ++ OffsetDisambiguation::Use, |
| 82 | ++ provider, |
| 83 | ++ ).unwrap(); |
| 84 | ++ |
| 85 | ++ let zdt3 = ZonedDateTime::from_utf8_with_provider( |
| 86 | ++ b"2010-03-04T23:10:00+08:00[Antarctica/Casey]", |
| 87 | ++ Disambiguation::Compatible, |
| 88 | ++ OffsetDisambiguation::Use, |
| 89 | ++ provider, |
| 90 | ++ ).unwrap(); |
| 91 | ++ |
| 92 | ++ let zdt4 = ZonedDateTime::from_utf8_with_provider( |
| 93 | ++ b"2010-03-05T00:45:00+08:00[Antarctica/Casey]", |
| 94 | ++ Disambiguation::Compatible, |
| 95 | ++ OffsetDisambiguation::Use, |
| 96 | ++ provider, |
| 97 | ++ ).unwrap(); |
| 98 | ++ |
| 99 | ++ let start_of_march4 = "2010-03-04T00:00:00+11:00[Antarctica/Casey]"; |
| 100 | ++ let start_of_march5 = "2010-03-05T00:00:00+11:00[Antarctica/Casey]"; |
| 101 | ++ let start_of_march6 = "2010-03-06T00:00:00+08:00[Antarctica/Casey]"; |
| 102 | ++ |
| 103 | ++ // Hours in day |
| 104 | ++ assert_eq!(zdt1.hours_in_day_with_provider(provider).unwrap(), 24.0); |
| 105 | ++ assert_eq!(zdt2.hours_in_day_with_provider(provider).unwrap(), 27.0); |
| 106 | ++ assert_eq!(zdt3.hours_in_day_with_provider(provider).unwrap(), 24.0); |
| 107 | ++ assert_eq!(zdt4.hours_in_day_with_provider(provider).unwrap(), 27.0); |
| 108 | ++ |
| 109 | ++ // Start of day |
| 110 | ++ assert_eq!(zdt1.start_of_day_with_provider(provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march4); |
| 111 | ++ assert_eq!(zdt2.start_of_day_with_provider(provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march5); |
| 112 | ++ assert_eq!(zdt3.start_of_day_with_provider(provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march4); |
| 113 | ++ assert_eq!(zdt4.start_of_day_with_provider(provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march5); |
| 114 | ++ |
| 115 | ++ // Rounding down |
| 116 | ++ for rounding_mode in [RoundingMode::Floor, RoundingMode::Trunc] { |
| 117 | ++ let options = RoundingOptions { |
| 118 | ++ smallest_unit: Some(Unit::Day), |
| 119 | ++ rounding_mode: Some(rounding_mode), |
| 120 | ++ ..Default::default() |
| 121 | ++ }; |
| 122 | ++ assert_eq!(zdt1.round_with_provider(options, provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march4); |
| 123 | ++ assert_eq!(zdt2.round_with_provider(options, provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march5); |
| 124 | ++ assert_eq!(zdt3.round_with_provider(options, provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march4); |
| 125 | ++ assert_eq!(zdt4.round_with_provider(options, provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march5); |
| 126 | ++ } |
| 127 | ++ |
| 128 | ++ // Rounding to nearest |
| 129 | ++ for rounding_mode in [ |
| 130 | ++ RoundingMode::HalfCeil, |
| 131 | ++ RoundingMode::HalfEven, |
| 132 | ++ RoundingMode::HalfExpand, |
| 133 | ++ RoundingMode::HalfFloor, |
| 134 | ++ RoundingMode::HalfTrunc, |
| 135 | ++ ] { |
| 136 | ++ let options = RoundingOptions { |
| 137 | ++ smallest_unit: Some(Unit::Day), |
| 138 | ++ rounding_mode: Some(rounding_mode), |
| 139 | ++ ..Default::default() |
| 140 | ++ }; |
| 141 | ++ assert_eq!(zdt1.round_with_provider(options, provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march5); |
| 142 | ++ assert_eq!(zdt2.round_with_provider(options, provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march5); |
| 143 | ++ assert_eq!(zdt3.round_with_provider(options, provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march5); |
| 144 | ++ assert_eq!(zdt4.round_with_provider(options, provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march5); |
| 145 | ++ } |
| 146 | ++ |
| 147 | ++ // Rounding up |
| 148 | ++ for rounding_mode in [RoundingMode::Ceil, RoundingMode::Expand] { |
| 149 | ++ let options = RoundingOptions { |
| 150 | ++ smallest_unit: Some(Unit::Day), |
| 151 | ++ rounding_mode: Some(rounding_mode), |
| 152 | ++ ..Default::default() |
| 153 | ++ }; |
| 154 | ++ assert_eq!(zdt1.round_with_provider(options, provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march5); |
| 155 | ++ assert_eq!(zdt2.round_with_provider(options, provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march6); |
| 156 | ++ assert_eq!(zdt3.round_with_provider(options, provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march5); |
| 157 | ++ assert_eq!(zdt4.round_with_provider(options, provider).unwrap().to_string_with_provider(provider).unwrap(), start_of_march6); |
| 158 | ++ } |
| 159 | ++ }) |
| 160 | ++} |
| 161 | +-- |
| 162 | +2.54.0.823.g6e5bcc1fc9-goog |
| 163 | + |
0 commit comments