updated tests for ZDT diffing w/ backoffs

This commit is contained in:
Adam Shaw 2024-03-29 12:43:58 -04:00 committed by Philip Chimento
parent 984f3cc284
commit 96718952b0
2 changed files with 43 additions and 22 deletions

View File

@ -19,10 +19,12 @@ TemporalHelpers.observeMethod(calls, dateLineZone, "getPossibleInstantsFor");
const zdt2 = new Temporal.ZonedDateTime(946722600_000_000_000n /* = 2000-01-01T02:30 local */, springFallZone); const zdt2 = new Temporal.ZonedDateTime(946722600_000_000_000n /* = 2000-01-01T02:30 local */, springFallZone);
// Future -> past, without wall-clock overshoot
// Expects valid intermediate Instant WITHOUT day correction (computed once)
{ {
const zdt1 = new Temporal.ZonedDateTime(949442400_000_000_000n /* = 2000-02-01T14:00 local */, springFallZone); const zdt1 = new Temporal.ZonedDateTime(949442400_000_000_000n /* = 2000-02-01T14:00 local */, springFallZone);
const result = zdt1.since(zdt2, { largestUnit: "years" }); const result = zdt1.since(zdt2, { largestUnit: "years" });
TemporalHelpers.assertDuration(result, 0, 1, 0, 0, 11, 30, 0, 0, 0, 0, "Normal case: no overflow, no DST"); TemporalHelpers.assertDuration(result, 0, 1, 0, 0, 11, 30, 0, 0, 0, 0, "no wall-clock overshoot, no DST");
assert.compareArray(calls, [ assert.compareArray(calls, [
"call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime "call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime
], "one intermediate should be tried"); ], "one intermediate should be tried");
@ -30,44 +32,50 @@ const zdt2 = new Temporal.ZonedDateTime(946722600_000_000_000n /* = 2000-01-01T0
calls.splice(0); // clear calls.splice(0); // clear
// Future -> past, WITH wall-clock overshoot
// Expects valid intermediate Instant with guaranteed 1-DAY correction (computed once)
{ {
const zdt1 = new Temporal.ZonedDateTime(949395600_000_000_000n /* = 2000-02-01T01:00 local */, springFallZone); const zdt1 = new Temporal.ZonedDateTime(949395600_000_000_000n /* = 2000-02-01T01:00 local */, springFallZone);
const result = zdt1.since(zdt2, { largestUnit: "years" }); const result = zdt1.since(zdt2, { largestUnit: "years" });
TemporalHelpers.assertDuration(result, 0, 0, 0, 30, 22, 30, 0, 0, 0, 0, "One day correction: overflow, no DST"); TemporalHelpers.assertDuration(result, 0, 0, 0, 30, 22, 30, 0, 0, 0, 0, "wall-clock overshoot, no DST");
assert.compareArray(calls, [ assert.compareArray(calls, [
"call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime "call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime
"call getPossibleInstantsFor", // second intermediate in DifferenceZonedDateTime ], "one intermediate should be tried");
], "two intermediates should be tried");
} }
calls.splice(0); // clear calls.splice(0); // clear
// Future -> past, WITH wall-clock overshoot
// Expects valid intermediate Instant with guaranteed 1-DAY correction (computed once)
// Intermediate Instant falls within spring DST gap and gets pushed forward,
// but since moving from future -> past, not possible to exacerbate overflow,
// so no other day corrections.
{ {
const end = new Temporal.ZonedDateTime(957258000_000_000_000n /* = 2000-05-02T02:00 local */, springFallZone); const end = new Temporal.ZonedDateTime(957258000_000_000_000n /* = 2000-05-02T02:00 local */, springFallZone);
const start = new Temporal.ZonedDateTime(954671400_000_000_000n /* = 2000-04-02T03:30-07:00 local */, springFallZone); const start = new Temporal.ZonedDateTime(954671400_000_000_000n /* = 2000-04-02T03:30-07:00 local */, springFallZone);
const result = end.since(start, { largestUnit: "years" }); const result = end.since(start, { largestUnit: "years" });
TemporalHelpers.assertDuration(result, 0, 0, 0, 29, 22, 30, 0, 0, 0, 0, "One day correction: no overflow, DST"); TemporalHelpers.assertDuration(result, 0, 0, 0, 29, 22, 30, 0, 0, 0, 0, "wall-clock overshoot, inconsiquential DST");
assert.compareArray(calls, [ assert.compareArray(calls, [
"call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime "call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime
"call getPossibleInstantsFor", // DisambiguatePossibleInstants on first intermediate ], "one intermediate should be tried");
"call getPossibleInstantsFor", // second intermediate in DifferenceZonedDateTime
], "two intermediates should be tried, with disambiguation");
} }
calls.splice(0); // clear calls.splice(0); // clear
// Two days correction: overflow and DST // Past -> future, WITH wall-clock overshoot
// (Not possible when going backwards. This test is just the same as the // Tries intermediate Instant with 1-DAY correction (first compute)
// corresponding one in until(), but negative.) // Then, ANOTHER day correction because updated intermediate Instant falls within dateline DST gap,
// pushing it forward, causing wall-clock overshoot again
// (Not possible when going backwards)
// (This test is just the same as the corresponding one in until(), but negative)
{ {
const start = new Temporal.ZonedDateTime(1325102400_000_000_000n /* = 2011-12-28T10:00 local */, dateLineZone); const start = new Temporal.ZonedDateTime(1325102400_000_000_000n /* = 2011-12-28T10:00 local */, dateLineZone);
const end = new Temporal.ZonedDateTime(1325257200_000_000_000n /* = 2011-12-31T05:00 local */, dateLineZone); const end = new Temporal.ZonedDateTime(1325257200_000_000_000n /* = 2011-12-31T05:00 local */, dateLineZone);
const result = start.since(end, { largestUnit: "days" }); const result = start.since(end, { largestUnit: "days" });
TemporalHelpers.assertDuration(result, 0, 0, 0, -1, -19, 0, 0, 0, 0, 0, "Two days correction: overflow and DST"); TemporalHelpers.assertDuration(result, 0, 0, 0, -1, -19, 0, 0, 0, 0, 0, "wall-clock overshoot, consiquential DST");
assert.compareArray(calls, [ assert.compareArray(calls, [
"call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime "call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime
"call getPossibleInstantsFor", // second intermediate in DifferenceZonedDateTime "call getPossibleInstantsFor", // second intermediate in DifferenceZonedDateTime
"call getPossibleInstantsFor", // DisambiguatePossibleInstants on second intermediate "call getPossibleInstantsFor", // DisambiguatePossibleInstants on second intermediate
"call getPossibleInstantsFor", // third intermediate in DifferenceZonedDateTime ], "two intermediates should be tried, with disambiguation");
], "three intermediates should be tried, with disambiguation");
} }

View File

@ -19,10 +19,12 @@ TemporalHelpers.observeMethod(calls, dateLineZone, "getPossibleInstantsFor");
const zdt1 = new Temporal.ZonedDateTime(946722600_000_000_000n /* = 2000-01-01T02:30 local */, springFallZone); const zdt1 = new Temporal.ZonedDateTime(946722600_000_000_000n /* = 2000-01-01T02:30 local */, springFallZone);
// Past -> future, without wall-clock overshoot
// Expects valid intermediate Instant WITHOUT day correction (computed once)
{ {
const zdt2 = new Temporal.ZonedDateTime(949442400_000_000_000n /* = 2000-02-01T14:00 local */, springFallZone); const zdt2 = new Temporal.ZonedDateTime(949442400_000_000_000n /* = 2000-02-01T14:00 local */, springFallZone);
const result = zdt1.until(zdt2, { largestUnit: "years" }); const result = zdt1.until(zdt2, { largestUnit: "years" });
TemporalHelpers.assertDuration(result, 0, 1, 0, 0, 11, 30, 0, 0, 0, 0, "Normal case: no overflow, no DST"); TemporalHelpers.assertDuration(result, 0, 1, 0, 0, 11, 30, 0, 0, 0, 0, "no wall-clock overshoot, no DST");
assert.compareArray(calls, [ assert.compareArray(calls, [
"call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime "call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime
], "one intermediate should be tried"); ], "one intermediate should be tried");
@ -30,22 +32,28 @@ const zdt1 = new Temporal.ZonedDateTime(946722600_000_000_000n /* = 2000-01-01T0
calls.splice(0); // clear calls.splice(0); // clear
// Past -> future, WITH wall-clock overshoot
// Expects valid intermediate Instant with guaranteed 1-DAY correction (computed once)
{ {
const zdt2 = new Temporal.ZonedDateTime(949395600_000_000_000n /* = 2000-02-01T01:00 local */, springFallZone); const zdt2 = new Temporal.ZonedDateTime(949395600_000_000_000n /* = 2000-02-01T01:00 local */, springFallZone);
const result = zdt1.until(zdt2, { largestUnit: "years" }); const result = zdt1.until(zdt2, { largestUnit: "years" });
TemporalHelpers.assertDuration(result, 0, 0, 0, 30, 22, 30, 0, 0, 0, 0, "One day correction: overflow, no DST"); TemporalHelpers.assertDuration(result, 0, 0, 0, 30, 22, 30, 0, 0, 0, 0, "wall-clock overshoot, no DST");
assert.compareArray(calls, [ assert.compareArray(calls, [
"call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime "call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime
"call getPossibleInstantsFor", // second intermediate in DifferenceZonedDateTime ], "one intermediate should be tried");
], "two intermediates should be tried");
} }
calls.splice(0); // clear calls.splice(0); // clear
// Past -> future, WITH wall-clock overshoot
// Tries intermediate Instant with 1-DAY correction (first compute)
// Then, ANOTHER correction because updated intermediate Instant falls within spring DST gap,
// pushing it forward, causing wall-clock overshoot again
// (Not possible when going backwards)
{ {
const zdt2 = new Temporal.ZonedDateTime(954669600_000_000_000n /* = 2000-04-02T02:00 local */, springFallZone); const zdt2 = new Temporal.ZonedDateTime(954669600_000_000_000n /* = 2000-04-02T02:00 local */, springFallZone);
const result = zdt1.until(zdt2, { largestUnit: "years" }); const result = zdt1.until(zdt2, { largestUnit: "years" });
TemporalHelpers.assertDuration(result, 0, 3, 0, 0, 23, 30, 0, 0, 0, 0, "One day correction: no overflow, DST"); TemporalHelpers.assertDuration(result, 0, 3, 0, 0, 23, 30, 0, 0, 0, 0, "wall-clock overshoot, small consiquential DST");
assert.compareArray(calls, [ assert.compareArray(calls, [
"call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime "call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime
"call getPossibleInstantsFor", // DisambiguatePossibleInstants on first intermediate "call getPossibleInstantsFor", // DisambiguatePossibleInstants on first intermediate
@ -55,15 +63,20 @@ calls.splice(0); // clear
calls.splice(0); // clear calls.splice(0); // clear
// Past -> future, WITH wall-clock overshoot
// Tries intermediate Instant with 1-DAY correction (first compute)
// Then, ANOTHER correction because updated intermediate Instant falls within dateline DST gap,
// pushing it forward, causing wall-clock overshoot again
// (Not possible when going backwards)
// (This test is just the same as the corresponding one in since(), but negative)
{ {
const start = new Temporal.ZonedDateTime(1325102400_000_000_000n /* = 2011-12-28T10:00 local */, dateLineZone); const start = new Temporal.ZonedDateTime(1325102400_000_000_000n /* = 2011-12-28T10:00 local */, dateLineZone);
const end = new Temporal.ZonedDateTime(1325257200_000_000_000n /* = 2011-12-31T05:00 local */, dateLineZone); const end = new Temporal.ZonedDateTime(1325257200_000_000_000n /* = 2011-12-31T05:00 local */, dateLineZone);
const result = start.until(end, { largestUnit: "days" }); const result = start.until(end, { largestUnit: "days" });
TemporalHelpers.assertDuration(result, 0, 0, 0, 1, 19, 0, 0, 0, 0, 0, "Two days correction: overflow and DST"); TemporalHelpers.assertDuration(result, 0, 0, 0, 1, 19, 0, 0, 0, 0, 0, "wall-clock overshoot, big consiquential DST");
assert.compareArray(calls, [ assert.compareArray(calls, [
"call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime "call getPossibleInstantsFor", // first intermediate in DifferenceZonedDateTime
"call getPossibleInstantsFor", // second intermediate in DifferenceZonedDateTime "call getPossibleInstantsFor", // second intermediate in DifferenceZonedDateTime
"call getPossibleInstantsFor", // DisambiguatePossibleInstants on second intermediate "call getPossibleInstantsFor", // DisambiguatePossibleInstants on second intermediate
"call getPossibleInstantsFor", // third intermediate in DifferenceZonedDateTime ], "two intermediates should be tried, with disambiguation");
], "three intermediates should be tried, with disambiguation");
} }