Temporal: Add toZonedDateTime tests.

This commit is contained in:
Ms2ger 2022-06-11 15:57:58 +02:00 committed by Philip Chimento
parent 6f2e6872fb
commit 697784363f
2 changed files with 47 additions and 0 deletions

View File

@ -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);

View File

@ -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);