From 697784363fbbbb1fe9ffba0dc80d35836e6c4e4a Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 11 Jun 2022 15:57:58 +0200 Subject: [PATCH] Temporal: Add toZonedDateTime tests. --- .../prototype/toZonedDateTime/calendar.js | 19 +++++++++++++ .../timezone-getpossibleinstantsfor.js | 28 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/calendar.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-getpossibleinstantsfor.js diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/calendar.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/calendar.js new file mode 100644 index 0000000000..dea05bec6d --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/calendar.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tozoneddatetime +description: Calendar of the receiver is used +features: [Temporal] +---*/ + +const calendar = new Temporal.Calendar("iso8601"); +const timeCalendar = { toString() { return "iso8601"; } }; +const plainDate = new Temporal.PlainDate(2000, 5, 2, calendar); +const result = plainDate.toZonedDateTime({ + timeZone: "UTC", + plainTime: { hour: 12, minute: 30, calendar: timeCalendar }, +}); +assert.sameValue(result.epochNanoseconds, 957270600_000_000_000n); +assert.sameValue(result.timeZone.toString(), "UTC"); +assert.sameValue(result.calendar, calendar); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-getpossibleinstantsfor.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-getpossibleinstantsfor.js new file mode 100644 index 0000000000..4431024715 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-getpossibleinstantsfor.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tozoneddatetime +description: Calendar of the receiver is used +features: [Temporal] +---*/ + +const calendar = new Temporal.Calendar("iso8601"); +class CustomTimeZone extends Temporal.TimeZone { + constructor() { + super("UTC"); + } + getPossibleInstantsFor(plainDateTime) { + assert.sameValue(plainDateTime.calendar, calendar); + return [new Temporal.Instant(987654321_000_000_000n)]; + } +} +const timeZone = new CustomTimeZone(); +const plainDate = new Temporal.PlainDate(2000, 5, 2, calendar); +const result = plainDate.toZonedDateTime({ + timeZone, + plainTime: { hour: 12, minute: 30 }, +}); +assert.sameValue(result.epochNanoseconds, 987654321_000_000_000n); +assert.sameValue(result.timeZone, timeZone); +assert.sameValue(result.calendar, calendar);