Skip to content

Commit 014536b

Browse files
committed
Add support for Temporal types
This adds support for: - Temporal.Duration - Temporal.Instant - Temporal.PlainDate - Temporal.PlainDateTime - Temporal.PlainYearMonth - Temporal.PlainMonthDay - Temporal.PlainTime - Temporal.ZonedDateTime
1 parent eab0e29 commit 014536b

File tree

24 files changed

+460
-3
lines changed

24 files changed

+460
-3
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ Currently the following types are supported:
5959
- [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
6060
- [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
6161
- [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
62+
- [`Temporal.Duration`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration)
63+
- [`Temporal.Instant`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Instant)
64+
- [`Temporal.PlainDate`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDate)
65+
- [`Temporal.PlainDateTime`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDateTime)
66+
- [`Temporal.PlainYearMonth`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainYearMonth)
67+
- [`Temporal.PlainMonthDay`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainMonthDay)
68+
- [`Temporal.PlainTime`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainTime)
69+
- [`Temporal.ZonedDateTime`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime)
6270
- [`Uint16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array)
6371
- [`Uint32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array)
6472
- [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.Duration(1, 2, 3, 4, 5, 6)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.Duration(1, 2, 3, 4, 5, 6)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.Duration(1, 2, 3, 4, 5, 6)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.Duration(1, 2, 3, 4, 5, 6)

fixtures/temporal-duration/input.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

fixtures/temporal-instant/input.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.Instant(1234567890123456789n)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.Instant(1234567890123456789n)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.PlainDate(2025, 1, 2)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.PlainDate(2025, 1, 2)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.PlainDateTime(2009, 8, 7, 6, 5)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.PlainDateTime(2009, 8, 7, 6, 5)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.PlainDateTime(2009, 8, 7, 6, 5, 4, 3, 2, 1)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.PlainDateTime(2009, 8, 7, 6, 5, 4, 3, 2, 1)
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.PlainDateTime(2008, 7, 6, 5, 4, 3, 2, 1, 0, 'japanese')
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.PlainDateTime(
10+
2008,
11+
7,
12+
6,
13+
5,
14+
4,
15+
3,
16+
2,
17+
1,
18+
0,
19+
'japanese'
20+
)

fixtures/temporal-plain-date/input.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.PlainDate(2025, 1, 2, 'hebrew')
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.PlainDate(2025, 1, 2, 'hebrew')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.PlainMonthDay(3, 14, 'iso8601', 2000)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.PlainMonthDay(3, 14, 'iso8601', 2000)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.PlainMonthDay(3, 14)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.PlainMonthDay(3, 14)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.PlainMonthDay(3, 14, 'japanese', 2000)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.PlainMonthDay(3, 14, 'japanese', 2000)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.PlainTime(1, 2, 3)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.PlainTime(1, 2, 3)

fixtures/temporal-plain-time/input.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.PlainTime(1, 2, 3, 4, 5, 6)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.PlainTime(1, 2, 3, 4, 5, 6)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.PlainYearMonth(1234, 5, 'iso8601', 6)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.PlainYearMonth(1234, 5, 'iso8601', 6)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.PlainYearMonth(1234, 5)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.PlainYearMonth(1234, 5)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.PlainYearMonth(1234, 5, 'islamicc', 6)
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.PlainYearMonth(1234, 5, 'islamicc', 6)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.ZonedDateTime(1234567890n, 'Europe/Amsterdam')
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.ZonedDateTime(1234567890n, 'Europe/Amsterdam')
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Temporal.ZonedDateTime(1234567890n, 'Europe/Amsterdam', 'gregory')
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Temporal.ZonedDateTime(
10+
1234567890n,
11+
'Europe/Amsterdam',
12+
'gregory'
13+
)

package-lock.json

+21-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"test": "c8 node --enable-source-maps dist/test.js"
3030
},
3131
"dependencies": {
32+
"@js-temporal/polyfill": "^0.4.0",
3233
"@types/estree": "^1.0.0"
3334
},
3435
"devDependencies": {

0 commit comments

Comments
 (0)