Skip to content

Commit 8b30689

Browse files
ioannadMs2ger
authored andcommitted
[Temporal] D.round, .total, .compare op order when relativeTo PD or ZDT
for X = prototype/round, prototype/total, compare, add test cases to `Duration/X/order-of-operations.js` that make sure that property bag properties aren't read when the relativeTo argument is a PlainDate or ZonedDateTime.
1 parent be2339b commit 8b30689

3 files changed

Lines changed: 53 additions & 1 deletion

File tree

test/built-ins/Temporal/Duration/compare/order-of-operations.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,27 @@ Temporal.Duration.compare(
8585
assert.compareArray(actual, expected, "order of operations");
8686
actual.splice(0); // clear
8787

88+
// basic order of operations, with relativeTo a Temporal object
89+
const pd = new Temporal.PlainDate(2026, 3, 6);
90+
Temporal.Duration.compare(
91+
createDurationPropertyBagObserver("one", 0, 0, 0, 0, 7),
92+
createDurationPropertyBagObserver("two", 0, 0, 0, 0, 6),
93+
createOptionsObserver(pd)
94+
);
95+
assert.compareArray(actual, expected,
96+
"relativeTo PlainDate should not read property bag fields");
97+
actual.splice(0); // clear
98+
99+
const zdt = new Temporal.ZonedDateTime(1772751600000000000n, "UTC");
100+
Temporal.Duration.compare(
101+
createDurationPropertyBagObserver("one", 0, 0, 0, 0, 7),
102+
createDurationPropertyBagObserver("two", 0, 0, 0, 0, 6),
103+
createOptionsObserver(zdt)
104+
);
105+
assert.compareArray(actual, expected,
106+
"relativeTo ZonedDateTime should not read property bag fields");
107+
actual.splice(0); // clear
108+
88109
const baseExpectedOpsWithRelativeTo = expected.concat([
89110
// ToRelativeTemporalObject
90111
"get options.relativeTo.calendar",

test/built-ins/Temporal/Duration/prototype/round/order-of-operations.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
/*---
55
esid: sec-temporal.duration.prototype.round
6-
description: Properties on objects passed to round() are accessed in the correct order
6+
description: >
7+
Properties on objects passed to round() are accessed in the correct order
8+
when relativeTo is a property bag.
79
includes: [compareArray.js, temporalHelpers.js]
810
features: [Temporal]
911
---*/
@@ -42,6 +44,21 @@ instance.round(createOptionsObserver({ smallestUnit: "microseconds" }));
4244
assert.compareArray(actual, expected, "order of operations");
4345
actual.splice(0); // clear
4446

47+
// basic order of operations, with relativeTo a Temporal.PlainDate object
48+
const pd = new Temporal.PlainDate(2026, 3, 6);
49+
instance.round(createOptionsObserver({ relativeTo: pd }));
50+
assert.compareArray(actual, expected,
51+
"relativeTo PlainDate should not read property bag fields");
52+
actual.splice(0); // clear
53+
54+
// basic order of operations, with relativeTo a Temporal.ZonedDateTime object
55+
const zdt = new Temporal.ZonedDateTime(1772751600000000000n, "UTC");
56+
instance.round(createOptionsObserver({ relativeTo: zdt }));
57+
assert.compareArray(actual, expected,
58+
"relativeTo ZonedDateTime should not read property bag fields");
59+
actual.splice(0); // clear
60+
61+
// basic order of operations, with relativeTo a plain property bag
4562
const expectedOpsForPlainRelativeTo = [
4663
"get options.largestUnit",
4764
"get options.largestUnit.toString",

test/built-ins/Temporal/Duration/prototype/total/order-of-operations.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ instance.total(createOptionsObserver({ unit: "nanoseconds" }));
3232
assert.compareArray(actual, expected, "order of operations");
3333
actual.splice(0); // clear
3434

35+
// basic order of operations, with relativeTo a Temporal object
36+
const pd = new Temporal.PlainDate(2026, 3, 6);
37+
instance.total(createOptionsObserver({ unit: "nanoseconds", relativeTo: pd }));
38+
assert.compareArray(actual, expected,
39+
"relativeTo PlainDate should not read property bag fields");
40+
actual.splice(0); // clear
41+
42+
const zdt = new Temporal.ZonedDateTime(1772751600000000000n, "UTC");
43+
instance.total(createOptionsObserver({ unit: "nanoseconds", relativeTo: zdt }));
44+
assert.compareArray(actual, expected,
45+
"relativeTo ZonedDateTime should not read property bag fields");
46+
actual.splice(0); // clear
47+
48+
3549
const expectedOpsForPlainRelativeTo = [
3650
// ToRelativeTemporalObject
3751
"get options.relativeTo",

0 commit comments

Comments
 (0)