summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/harness/temporalHelpers-cross-date-line-time-zone.js
blob: b2c0abd29488e9dfe13577860486c70aa7275580 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// |reftest| skip -- Temporal is not supported
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
  Verify the time zone arithmetic used in
  TemporalHelpers.crossDateLineTimeZone() against the Pacific/Apia time zone in
  the implementation's time zone database
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

// No need to test this on hosts that don't provide an Intl object. It's
// sufficient that the logic is tested on at least one host.
if (typeof globalThis.Intl !== "undefined") {
  const tz = TemporalHelpers.crossDateLineTimeZone();
  const realTz = new Temporal.TimeZone('Pacific/Apia');
  const shiftInstant = Temporal.Instant.from('2011-12-30T10:00:00Z');

  assert.sameValue(
    tz.getOffsetNanosecondsFor(shiftInstant),
    realTz.getOffsetNanosecondsFor(shiftInstant),
    'offset at shift instant'
  );
  const minus1 = shiftInstant.subtract({ hours: 1 });
  assert.sameValue(
    tz.getOffsetNanosecondsFor(minus1),
    realTz.getOffsetNanosecondsFor(minus1),
    'offset at 1 hour before shift'
  );
  const plus1 = shiftInstant.add({ hours: 1 });
  assert.sameValue(
    tz.getOffsetNanosecondsFor(plus1),
    realTz.getOffsetNanosecondsFor(plus1),
    'offset at 1 hour after shift'
  );

  const middleOfSkippedDayWallTime = Temporal.PlainDateTime.from("2011-12-30T12:00");
  assert.compareArray(
    tz.getPossibleInstantsFor(middleOfSkippedDayWallTime).map((i) => i.epochNanoseconds),
    realTz.getPossibleInstantsFor(middleOfSkippedDayWallTime).map((i) => i.epochNanoseconds),
    'possible instants for middle of skipped day wall time'
  );
  const before1 = middleOfSkippedDayWallTime.subtract({ days: 1 });
  assert.compareArray(
    tz.getPossibleInstantsFor(before1).map((i) => i.epochNanoseconds),
    realTz.getPossibleInstantsFor(before1).map((i) => i.epochNanoseconds),
    'possible instants for 1 day before skipped day'
  );
  const after1 = middleOfSkippedDayWallTime.add({ days: 1 });
  assert.compareArray(
    tz.getPossibleInstantsFor(after1).map((i) => i.epochNanoseconds),
    realTz.getPossibleInstantsFor(after1).map((i) => i.epochNanoseconds),
    'possible instants for 1 day after skipped day'
  );
}

reportCompare(0, 0);