diff --git a/polyfill/test/Instant/constructor/fromEpochMicroseconds/basic.js b/polyfill/test/Instant/constructor/fromEpochMicroseconds/basic.js new file mode 100644 index 0000000000..73ffb79e09 --- /dev/null +++ b/polyfill/test/Instant/constructor/fromEpochMicroseconds/basic.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.fromepochmicroseconds +description: Basic tests for Instant.fromEpochMicroseconds(). +features: [BigInt, Temporal] +---*/ + +const afterEpoch = Temporal.Instant.fromEpochMicroseconds(217175010_123_456n); +assert.sameValue(afterEpoch.epochNanoseconds, 217175010_123_456_000n, "fromEpochMicroseconds post epoch"); + +const beforeEpoch = Temporal.Instant.fromEpochMicroseconds(-217175010_876_543n); +assert.sameValue(beforeEpoch.epochNanoseconds, -217175010_876_543_000n, "fromEpochMicroseconds pre epoch"); diff --git a/polyfill/test/Instant/constructor/fromEpochMilliseconds/basic.js b/polyfill/test/Instant/constructor/fromEpochMilliseconds/basic.js new file mode 100644 index 0000000000..2da12ffb4f --- /dev/null +++ b/polyfill/test/Instant/constructor/fromEpochMilliseconds/basic.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.fromepochmilliseconds +description: Basic tests for Instant.fromEpochMilliseconds(). +features: [BigInt, Temporal] +---*/ + +const afterEpoch = Temporal.Instant.fromEpochMilliseconds(217175010_123); +assert.sameValue(afterEpoch.epochNanoseconds, 217175010_123_000_000n, "fromEpochMilliseconds post epoch"); + +const beforeEpoch = Temporal.Instant.fromEpochMilliseconds(-217175010_876); +assert.sameValue(beforeEpoch.epochNanoseconds, -217175010_876_000_000n, "fromEpochMilliseconds pre epoch"); diff --git a/polyfill/test/Instant/constructor/fromEpochNanoseconds/basic.js b/polyfill/test/Instant/constructor/fromEpochNanoseconds/basic.js new file mode 100644 index 0000000000..229c408940 --- /dev/null +++ b/polyfill/test/Instant/constructor/fromEpochNanoseconds/basic.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.fromepochnanoseconds +description: Basic tests for Instant.fromEpochNanoseconds(). +features: [BigInt, Temporal] +---*/ + +const afterEpoch = Temporal.Instant.fromEpochNanoseconds(217175010_123_456_789n); +assert.sameValue(afterEpoch.epochNanoseconds, 217175010_123_456_789n, "fromEpochNanoseconds post epoch"); + +const beforeEpoch = Temporal.Instant.fromEpochNanoseconds(-217175010_876_543_211n); +assert.sameValue(beforeEpoch.epochNanoseconds, -217175010_876_543_211n, "fromEpochNanoseconds pre epoch"); diff --git a/polyfill/test/Instant/constructor/fromEpochSeconds/basic.js b/polyfill/test/Instant/constructor/fromEpochSeconds/basic.js new file mode 100644 index 0000000000..ad9f175660 --- /dev/null +++ b/polyfill/test/Instant/constructor/fromEpochSeconds/basic.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.fromepochseconds +description: Basic tests for Instant.fromEpochSeconds(). +features: [BigInt, Temporal] +---*/ + +const afterEpoch = Temporal.Instant.fromEpochSeconds(217175010); +assert.sameValue(afterEpoch.epochNanoseconds, 217175010_000_000_000n, "fromEpochSeconds post epoch"); + +const beforeEpoch = Temporal.Instant.fromEpochSeconds(-217175010); +assert.sameValue(beforeEpoch.epochNanoseconds, -217175010_000_000_000n, "fromEpochSeconds pre epoch"); diff --git a/polyfill/test/Instant/prototype/epochMicroseconds/basic.js b/polyfill/test/Instant/prototype/epochMicroseconds/basic.js new file mode 100644 index 0000000000..ca4a582ab6 --- /dev/null +++ b/polyfill/test/Instant/prototype/epochMicroseconds/basic.js @@ -0,0 +1,16 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-temporal.instant.prototype.epochmicroseconds +description: Basic tests for epochMicroseconds. +features: [BigInt, Temporal] +---*/ + +const afterEpoch = new Temporal.Instant(217175010_123_456_789n); +assert.sameValue(afterEpoch.epochMicroseconds, 217175010_123_456n, "epochMicroseconds post epoch"); +assert.sameValue(typeof afterEpoch.epochMicroseconds, "bigint", "epochMicroseconds value is a bigint"); + +const beforeEpoch = new Temporal.Instant(-217175010_876_543_211n); +assert.sameValue(beforeEpoch.epochMicroseconds, -217175010_876_543n, "epochMicroseconds pre epoch"); +assert.sameValue(typeof beforeEpoch.epochMicroseconds, "bigint", "epochMicroseconds value is a bigint"); diff --git a/polyfill/test/Instant/prototype/epochMilliseconds/basic.js b/polyfill/test/Instant/prototype/epochMilliseconds/basic.js new file mode 100644 index 0000000000..418a5a95e4 --- /dev/null +++ b/polyfill/test/Instant/prototype/epochMilliseconds/basic.js @@ -0,0 +1,16 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-temporal.instant.prototype.epochmilliseconds +description: Basic tests for epochMilliseconds. +features: [BigInt, Temporal] +---*/ + +const afterEpoch = new Temporal.Instant(217175010_123_456_789n); +assert.sameValue(afterEpoch.epochMilliseconds, 217175010_123, "epochMilliseconds post epoch"); +assert.sameValue(typeof afterEpoch.epochMilliseconds, "number", "epochMilliseconds value is a number"); + +const beforeEpoch = new Temporal.Instant(-217175010_876_543_211n); +assert.sameValue(beforeEpoch.epochMilliseconds, -217175010_876, "epochMilliseconds pre epoch"); +assert.sameValue(typeof beforeEpoch.epochMilliseconds, "number", "epochMilliseconds value is a number"); diff --git a/polyfill/test/Instant/prototype/epochNanoseconds/basic.js b/polyfill/test/Instant/prototype/epochNanoseconds/basic.js new file mode 100644 index 0000000000..dcbbfe4aab --- /dev/null +++ b/polyfill/test/Instant/prototype/epochNanoseconds/basic.js @@ -0,0 +1,16 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-temporal.instant.prototype.epochnanoseconds +description: Basic tests for epochNanoseconds. +features: [BigInt, Temporal] +---*/ + +const afterEpoch = new Temporal.Instant(217175010_123_456_789n); +assert.sameValue(afterEpoch.epochNanoseconds, 217175010_123_456_789n, "epochNanoseconds post epoch"); +assert.sameValue(typeof afterEpoch.epochNanoseconds, "bigint", "epochNanoseconds value is a bigint"); + +const beforeEpoch = new Temporal.Instant(-217175010_876_543_211n); +assert.sameValue(beforeEpoch.epochNanoseconds, -217175010_876_543_211n, "epochNanoseconds pre epoch"); +assert.sameValue(typeof beforeEpoch.epochNanoseconds, "bigint", "epochNanoseconds value is a bigint"); diff --git a/polyfill/test/Instant/prototype/epochSeconds/basic.js b/polyfill/test/Instant/prototype/epochSeconds/basic.js new file mode 100644 index 0000000000..7c3e8ab798 --- /dev/null +++ b/polyfill/test/Instant/prototype/epochSeconds/basic.js @@ -0,0 +1,16 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-temporal.instant.prototype.epochseconds +description: Basic tests for epochSeconds. +features: [BigInt, Temporal] +---*/ + +const afterEpoch = new Temporal.Instant(217175010_123_456_789n); +assert.sameValue(afterEpoch.epochSeconds, 217175010, "epochSeconds post epoch"); +assert.sameValue(typeof afterEpoch.epochSeconds, "number", "epochSeconds value is a number"); + +const beforeEpoch = new Temporal.Instant(-217175010_876_543_211n); +assert.sameValue(beforeEpoch.epochSeconds, -217175010, "epochSeconds pre epoch"); +assert.sameValue(typeof beforeEpoch.epochSeconds, "number", "epochSeconds value is a number"); diff --git a/polyfill/test/Instant/prototype/toString/basic.js b/polyfill/test/Instant/prototype/toString/basic.js new file mode 100644 index 0000000000..8b4ca47a84 --- /dev/null +++ b/polyfill/test/Instant/prototype/toString/basic.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.tostring +description: Basic tests for toString(). +features: [BigInt, Temporal] +---*/ + +const afterEpoch = new Temporal.Instant(217175010_123_456_789n); +assert.sameValue(afterEpoch.toString(), "1976-11-18T14:23:30.123456789Z", "basic toString() after epoch"); + +const beforeEpoch = new Temporal.Instant(-217175010_876_543_211n); +assert.sameValue(beforeEpoch.toString(), "1963-02-13T09:36:29.123456789Z", "basic toString() before epoch"); diff --git a/polyfill/test/ZonedDateTime/prototype/epochMicroseconds/basic.js b/polyfill/test/ZonedDateTime/prototype/epochMicroseconds/basic.js new file mode 100644 index 0000000000..2c31cef34a --- /dev/null +++ b/polyfill/test/ZonedDateTime/prototype/epochMicroseconds/basic.js @@ -0,0 +1,16 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-temporal.zoneddatetime.prototype.epochmicroseconds +description: Basic tests for epochMicroseconds. +features: [BigInt, Temporal] +---*/ + +const afterEpoch = new Temporal.ZonedDateTime(217175010_123_456_789n, "UTC"); +assert.sameValue(afterEpoch.epochMicroseconds, 217175010_123_456n, "epochMicroseconds post epoch"); +assert.sameValue(typeof afterEpoch.epochMicroseconds, "bigint", "epochMicroseconds value is a bigint"); + +const beforeEpoch = new Temporal.ZonedDateTime(-217175010_876_543_211n, "UTC"); +assert.sameValue(beforeEpoch.epochMicroseconds, -217175010_876_543n, "epochMicroseconds pre epoch"); +assert.sameValue(typeof beforeEpoch.epochMicroseconds, "bigint", "epochMicroseconds value is a bigint"); diff --git a/polyfill/test/ZonedDateTime/prototype/epochMilliseconds/basic.js b/polyfill/test/ZonedDateTime/prototype/epochMilliseconds/basic.js new file mode 100644 index 0000000000..2208a5cb8c --- /dev/null +++ b/polyfill/test/ZonedDateTime/prototype/epochMilliseconds/basic.js @@ -0,0 +1,16 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-temporal.zoneddatetime.prototype.epochmilliseconds +description: Basic tests for epochMilliseconds. +features: [BigInt, Temporal] +---*/ + +const afterEpoch = new Temporal.ZonedDateTime(217175010_123_456_789n, "UTC"); +assert.sameValue(afterEpoch.epochMilliseconds, 217175010_123, "epochMilliseconds post epoch"); +assert.sameValue(typeof afterEpoch.epochMilliseconds, "number", "epochMilliseconds value is a number"); + +const beforeEpoch = new Temporal.ZonedDateTime(-217175010_876_543_211n, "UTC"); +assert.sameValue(beforeEpoch.epochMilliseconds, -217175010_876, "epochMilliseconds pre epoch"); +assert.sameValue(typeof beforeEpoch.epochMilliseconds, "number", "epochMilliseconds value is a number"); diff --git a/polyfill/test/ZonedDateTime/prototype/epochNanoseconds/basic.js b/polyfill/test/ZonedDateTime/prototype/epochNanoseconds/basic.js new file mode 100644 index 0000000000..cc5cf2c32f --- /dev/null +++ b/polyfill/test/ZonedDateTime/prototype/epochNanoseconds/basic.js @@ -0,0 +1,16 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-temporal.zoneddatetime.prototype.epochnanoseconds +description: Basic tests for epochNanoseconds. +features: [BigInt, Temporal] +---*/ + +const afterEpoch = new Temporal.ZonedDateTime(217175010_123_456_789n, "UTC"); +assert.sameValue(afterEpoch.epochNanoseconds, 217175010_123_456_789n, "epochNanoseconds post epoch"); +assert.sameValue(typeof afterEpoch.epochNanoseconds, "bigint", "epochNanoseconds value is a bigint"); + +const beforeEpoch = new Temporal.ZonedDateTime(-217175010_876_543_211n, "UTC"); +assert.sameValue(beforeEpoch.epochNanoseconds, -217175010_876_543_211n, "epochNanoseconds pre epoch"); +assert.sameValue(typeof beforeEpoch.epochNanoseconds, "bigint", "epochNanoseconds value is a bigint"); diff --git a/polyfill/test/ZonedDateTime/prototype/epochSeconds/basic.js b/polyfill/test/ZonedDateTime/prototype/epochSeconds/basic.js new file mode 100644 index 0000000000..651c254f89 --- /dev/null +++ b/polyfill/test/ZonedDateTime/prototype/epochSeconds/basic.js @@ -0,0 +1,16 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-temporal.zoneddatetime.prototype.epochseconds +description: Basic tests for epochSeconds. +features: [BigInt, Temporal] +---*/ + +const afterEpoch = new Temporal.ZonedDateTime(217175010_123_456_789n, "UTC"); +assert.sameValue(afterEpoch.epochSeconds, 217175010, "epochSeconds post epoch"); +assert.sameValue(typeof afterEpoch.epochSeconds, "number", "epochSeconds value is a number"); + +const beforeEpoch = new Temporal.ZonedDateTime(-217175010_876_543_211n, "UTC"); +assert.sameValue(beforeEpoch.epochSeconds, -217175010, "epochSeconds pre epoch"); +assert.sameValue(typeof beforeEpoch.epochSeconds, "number", "epochSeconds value is a number"); diff --git a/polyfill/test/instant.mjs b/polyfill/test/instant.mjs index cc99f87602..84fe2e833e 100644 --- a/polyfill/test/instant.mjs +++ b/polyfill/test/instant.mjs @@ -19,18 +19,6 @@ const { Instant } = Temporal; describe('Instant', () => { describe('instant.toString() works', () => { - it('`1976-11-18T14:23:30.123456789Z`.toString()', () => { - const iso = '1976-11-18T14:23:30.123456789Z'; - const instant = Instant.from(iso); - assert(instant); - equal(`${instant}`, iso); - }); - it('`1963-02-13T09:36:29.123456789Z`.toString()', () => { - const iso = '1963-02-13T09:36:29.123456789Z'; - const instant = Instant.from(iso); - assert(instant); - equal(`${instant}`, iso); - }); it('optional time zone parameter UTC', () => { const inst = Instant.from('1976-11-18T14:23:30.123456789Z'); const timeZone = Temporal.TimeZone.from('UTC'); @@ -100,122 +88,6 @@ describe('Instant', () => { [{}, () => {}, undefined].forEach((options) => equal(i1.toString(options), '1976-11-18T15:23:00Z')); }); }); - describe('Instant.epochSeconds works', () => { - it('post-epoch', () => { - const epochMs = Date.UTC(1976, 10, 18, 15, 23, 30, 123); - const epochNs = BigInt(epochMs) * BigInt(1e6); - const inst = new Instant(epochNs); - equal(inst.epochSeconds, Math.trunc(epochMs / 1e3)); - equal(typeof inst.epochSeconds, 'number'); - }); - it('pre-epoch', () => { - const epochMs = Date.UTC(1963, 1, 13, 9, 36, 29, 123); - const epochNs = BigInt(epochMs) * BigInt(1e6); - const inst = new Instant(epochNs); - equal(inst.epochSeconds, Math.trunc(epochMs / 1e3)); - equal(typeof inst.epochSeconds, 'number'); - }); - }); - describe('Instant.fromEpochSeconds() works', () => { - it('1976-11-18T15:23:30', () => { - const epochSeconds = Math.floor(Date.UTC(1976, 10, 18, 15, 23, 30, 123) / 1e3); - const instant = Instant.fromEpochSeconds(epochSeconds); - equal(instant.epochSeconds, epochSeconds); - }); - it('1963-02-13T09:36:29', () => { - const epochSeconds = Math.floor(Date.UTC(1963, 1, 13, 9, 36, 29, 123) / 1e3); - const instant = Instant.fromEpochSeconds(epochSeconds); - equal(instant.epochSeconds, epochSeconds); - }); - }); - describe('Instant.epochMilliseconds() works', () => { - it('post-epoch', () => { - const epochMs = Date.UTC(1976, 10, 18, 15, 23, 30, 123); - const epochNs = BigInt(epochMs) * BigInt(1e6); - const inst = new Instant(epochNs); - equal(inst.epochMilliseconds, epochMs); - equal(typeof inst.epochMilliseconds, 'number'); - }); - it('pre-epoch', () => { - const epochMs = Date.UTC(1963, 1, 13, 9, 36, 29, 123); - const epochNs = BigInt(epochMs) * BigInt(1e6); - const inst = new Instant(epochNs); - equal(inst.epochMilliseconds, epochMs); - equal(typeof inst.epochMilliseconds, 'number'); - }); - }); - describe('Instant.fromEpochMilliseconds() works', () => { - it('1976-11-18T15:23:30.123', () => { - const epochMilliseconds = Date.UTC(1976, 10, 18, 15, 23, 30, 123); - const instant = Instant.fromEpochMilliseconds(epochMilliseconds); - equal(instant.epochMilliseconds, epochMilliseconds); - }); - it('1963-02-13T09:36:29.123', () => { - const epochMilliseconds = Date.UTC(1963, 1, 13, 9, 36, 29, 123); - const instant = Instant.fromEpochMilliseconds(epochMilliseconds); - equal(instant.epochMilliseconds, epochMilliseconds); - }); - }); - describe('Instant.epochMicroseconds works', () => { - it('post-epoch', () => { - const epochMs = Date.UTC(1976, 10, 18, 15, 23, 30, 123); - const epochNs = BigInt(epochMs) * BigInt(1e6); - const inst = new Instant(epochNs); - equal(inst.epochMicroseconds, BigInt(epochMs) * BigInt(1e3)); - equal(typeof inst.epochMicroseconds, 'bigint'); - }); - it('pre-epoch', () => { - const epochMs = Date.UTC(1963, 1, 13, 9, 36, 29, 123); - const epochNs = BigInt(epochMs) * BigInt(1e6); - const inst = new Instant(epochNs); - equal(inst.epochMicroseconds, BigInt(epochMs) * BigInt(1e3)); - equal(typeof inst.epochMicroseconds, 'bigint'); - }); - }); - describe('Instant.fromEpochMicroseconds() works', () => { - it('1976-11-18T15:23:30.123456', () => { - const epochMicroseconds = BigInt(Date.UTC(1976, 10, 18, 15, 23, 30, 123)) * BigInt(1e3) + BigInt(456); - const instant = Instant.fromEpochMicroseconds(epochMicroseconds); - equal(instant.epochMicroseconds, epochMicroseconds); - }); - it('1963-02-13T09:36:29.123456', () => { - const epochMicroseconds = BigInt(Date.UTC(1963, 1, 13, 9, 36, 29, 123)) * BigInt(1e3) + BigInt(456); - const instant = Instant.fromEpochMicroseconds(epochMicroseconds); - equal(instant.epochMicroseconds, epochMicroseconds); - }); - }); - describe('Instant.epochNanoseconds works', () => { - it('post-epoch', () => { - const epochMs = Date.UTC(1976, 10, 18, 15, 23, 30, 123); - const epochNs = BigInt(epochMs) * BigInt(1e6); - const inst = new Instant(epochNs); - equal(inst.epochNanoseconds, epochNs); - equal(typeof inst.epochNanoseconds, 'bigint'); - }); - it('pre-epoch', () => { - const epochMs = Date.UTC(1963, 1, 13, 9, 36, 29, 123); - const epochNs = BigInt(epochMs) * BigInt(1e6); - const inst = new Instant(epochNs); - equal(inst.epochNanoseconds, epochNs); - equal(typeof inst.epochNanoseconds, 'bigint'); - }); - }); - describe('Instant.fromEpochNanoseconds() works', () => { - it('1976-11-18T15:23:30.123456789', () => { - const epochNanoseconds = BigInt(Date.UTC(1976, 10, 18, 15, 23, 30, 123)) * BigInt(1e6) + BigInt(456789); - const instant = Instant.fromEpochNanoseconds(epochNanoseconds); - equal(instant.epochNanoseconds, epochNanoseconds); - }); - it('1963-02-13T09:36:29.123456789', () => { - const epochNanoseconds = BigInt(Date.UTC(1963, 1, 13, 9, 36, 29, 123)) * BigInt(1e6) + BigInt(456789); - const instant = Instant.fromEpochNanoseconds(epochNanoseconds); - equal(instant.epochNanoseconds, epochNanoseconds); - }); - it('-1n', () => { - const instant = Instant.fromEpochNanoseconds(-1n); - equal(`${instant}`, '1969-12-31T23:59:59.999999999Z'); - }); - }); describe('Instant.from() works', () => { it('1976-11-18T15:23Z', () => { equal(Instant.from('1976-11-18T15:23Z').epochMilliseconds, Date.UTC(1976, 10, 18, 15, 23));