summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/instant-string.js
blob: 943fb73750f16b593b0e52c1ca2e68ca323197d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
// 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.timezone.prototype.getoffsetnanosecondsfor
description: Conversion of ISO date-time strings to Temporal.Instant instances
features: [Temporal]
---*/

const instance = new Temporal.TimeZone("America/Vancouver");

let str = "1970-01-01T00:00";
assert.throws(RangeError, () => instance.getOffsetNanosecondsFor(str), "bare date-time string is not an instant");
str = "1970-01-01T00:00[America/Vancouver]";
assert.throws(RangeError, () => instance.getOffsetNanosecondsFor(str), "date-time + IANA annotation is not an instant");

// The following are all valid strings so should not throw:

const valids = [
  "1970-01-01T00:00Z",
  "1970-01-01T00:00+01:00",
  "1970-01-01T00:00Z[America/Vancouver]",
  "1970-01-01T00:00+01:00[America/Vancouver]",
];
for (const str of valids) {
  const result = instance.getOffsetNanosecondsFor(str);
  assert.sameValue(result, -28800e9);
}

reportCompare(0, 0);