Skip to content

Commit e723219

Browse files
ptomatoMs2ger
authored andcommitted
Temporal: Add tests for serialization of durations with pairs of units
These check that durations with large and small units are properly serialized.
1 parent 61d0eb9 commit e723219

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.duration.prototype.tojson
6+
description: Pairs of units with one large and one small
7+
features: [Temporal]
8+
---*/
9+
10+
assert.sameValue(
11+
new Temporal.Duration(1, 0, 0, 0, 0, 0, 0, 0, 0, 1).toJSON(),
12+
"P1YT0.000000001S",
13+
"years with nanoseconds"
14+
);
15+
16+
assert.sameValue(
17+
new Temporal.Duration(0, 1, 0, 0, 0, 0, 0, 0, 1).toJSON(),
18+
"P1MT0.000001S",
19+
"months with microseconds"
20+
);
21+
22+
assert.sameValue(
23+
new Temporal.Duration(0, 0, 1, 0, 0, 0, 0, 1).toJSON(),
24+
"P1WT0.001S",
25+
"weeks with milliseconds"
26+
);
27+
28+
assert.sameValue(
29+
new Temporal.Duration(0, 0, 0, 1, 0, 0, 1).toJSON(),
30+
"P1DT1S",
31+
"days with seconds"
32+
);
33+
34+
assert.sameValue(
35+
new Temporal.Duration(0, 0, 0, 0, 1, 1).toJSON(),
36+
"PT1H1M",
37+
"hours with minutes"
38+
);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.duration.prototype.tostring
6+
description: Pairs of units with one large and one small
7+
features: [Temporal]
8+
---*/
9+
10+
assert.sameValue(
11+
new Temporal.Duration(1, 0, 0, 0, 0, 0, 0, 0, 0, 1).toString(),
12+
"P1YT0.000000001S",
13+
"years with nanoseconds"
14+
);
15+
16+
assert.sameValue(
17+
new Temporal.Duration(0, 1, 0, 0, 0, 0, 0, 0, 1).toString(),
18+
"P1MT0.000001S",
19+
"months with microseconds"
20+
);
21+
22+
assert.sameValue(
23+
new Temporal.Duration(0, 0, 1, 0, 0, 0, 0, 1).toString(),
24+
"P1WT0.001S",
25+
"weeks with milliseconds"
26+
);
27+
28+
assert.sameValue(
29+
new Temporal.Duration(0, 0, 0, 1, 0, 0, 1).toString(),
30+
"P1DT1S",
31+
"days with seconds"
32+
);
33+
34+
assert.sameValue(
35+
new Temporal.Duration(0, 0, 0, 0, 1, 1).toString(),
36+
"PT1H1M",
37+
"hours with minutes"
38+
);

0 commit comments

Comments
 (0)