Skip to content

Commit f5dcae0

Browse files
committed
Use beyondDaySpan in NudgeToZonedDateTime
1 parent 9f17b3c commit f5dcae0

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/builtins/compiled/zoneddatetime.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ impl ZonedDateTime {
389389
mod tests {
390390
use super::ZonedDateTime;
391391
use crate::options::{
392-
Disambiguation, DisplayCalendar, DisplayOffset, DisplayTimeZone, OffsetDisambiguation, Unit,
392+
DifferenceSettings, Disambiguation, DisplayCalendar, DisplayOffset, DisplayTimeZone,
393+
OffsetDisambiguation, RoundingMode, Unit,
393394
};
394395
use crate::provider::TransitionDirection;
395396
use crate::Calendar;
@@ -922,4 +923,23 @@ mod tests {
922923
.unwrap();
923924
assert_eq!(next.to_string(), TROLL_FIRST_TRANSITION);
924925
}
926+
927+
#[test]
928+
fn test_zdt_until_rounding() {
929+
// Regression test for beyondDaySpan rounding behavior
930+
let start = parse_zdt_with_reject("2020-01-01T00:00-08:00[-08:00]").unwrap();
931+
let end = parse_zdt_with_reject("2020-01-03T23:59-08:00[-08:00]").unwrap();
932+
let difference = start
933+
.until(
934+
&end,
935+
DifferenceSettings {
936+
largest_unit: Some(Unit::Day),
937+
smallest_unit: Some(Unit::Hour),
938+
rounding_mode: Some(RoundingMode::HalfExpand),
939+
..Default::default()
940+
},
941+
)
942+
.unwrap();
943+
assert_eq!(difference.to_string(), "P3D");
944+
}
925945
}

src/builtins/core/duration/normalized.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ impl NormalizedDurationRecord {
686686
// a. Let didRoundBeyondDay be true.
687687
// b. Let dayDelta be sign.
688688
// c. Set roundedTimeDuration to ? RoundTimeDurationToIncrement(beyondDaySpan, increment × unitLength, roundingMode).
689-
let rounded_time = self.norm.round_inner(
689+
let rounded_time = beyond_day_span.round_inner(
690690
unsafe {
691691
NonZeroU128::new_unchecked(unit_length.into())
692692
.checked_mul(options.increment.as_extended_increment())

0 commit comments

Comments
 (0)