mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 21:59:07 +00:00
LibJS: Implement the Temporal.ZonedDateTime constructor
And the simple Temporal.ZonedDateTime.prototype getters, so that the constructed Temporal.ZonedDateTime may actually be validated.
This commit is contained in:
parent
8ab765a3eb
commit
8c73cae2b8
Notes:
github-actions[bot]
2024-11-26 10:04:22 +00:00
Author: https://github.com/trflynn89
Commit: 8c73cae2b8
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2577
Reviewed-by: https://github.com/shannonbooth ✅
48 changed files with 1757 additions and 23 deletions
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 2", () => {
|
||||
expect(Temporal.ZonedDateTime.compare).toHaveLength(2);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
const zonedDateTimeOne = new Temporal.ZonedDateTime(1n, "UTC");
|
||||
const zonedDateTimeTwo = new Temporal.ZonedDateTime(2n, "UTC");
|
||||
|
||||
expect(Temporal.ZonedDateTime.compare(zonedDateTimeOne, zonedDateTimeOne)).toBe(0);
|
||||
expect(Temporal.ZonedDateTime.compare(zonedDateTimeTwo, zonedDateTimeTwo)).toBe(0);
|
||||
expect(Temporal.ZonedDateTime.compare(zonedDateTimeOne, zonedDateTimeTwo)).toBe(-1);
|
||||
expect(Temporal.ZonedDateTime.compare(zonedDateTimeTwo, zonedDateTimeOne)).toBe(1);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,132 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 1", () => {
|
||||
expect(Temporal.ZonedDateTime.from).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("ZonedDateTime instance argument", () => {
|
||||
const timeZone = "UTC";
|
||||
const calendar = "gregory";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1627318123456789000n, timeZone, calendar);
|
||||
const createdZoneDateTime = Temporal.ZonedDateTime.from(zonedDateTime);
|
||||
|
||||
expect(createdZoneDateTime).toBeInstanceOf(Temporal.ZonedDateTime);
|
||||
expect(createdZoneDateTime).not.toBe(zonedDateTime);
|
||||
expect(createdZoneDateTime.timeZoneId).toBe(timeZone);
|
||||
expect(createdZoneDateTime.calendarId).toBe(calendar);
|
||||
expect(createdZoneDateTime.epochNanoseconds).toBe(1627318123456789000n);
|
||||
});
|
||||
|
||||
test("PlainDate instance argument", () => {
|
||||
const timeZone = "UTC";
|
||||
const calendar = "gregory";
|
||||
const plainDate = new Temporal.PlainDate(2021, 11, 7, calendar);
|
||||
plainDate.timeZone = timeZone;
|
||||
const createdZoneDateTime = Temporal.ZonedDateTime.from(plainDate);
|
||||
|
||||
expect(createdZoneDateTime).toBeInstanceOf(Temporal.ZonedDateTime);
|
||||
expect(createdZoneDateTime.timeZoneId).toBe(timeZone);
|
||||
expect(createdZoneDateTime.calendarId).toBe(calendar);
|
||||
expect(createdZoneDateTime.year).toBe(2021);
|
||||
expect(createdZoneDateTime.month).toBe(11);
|
||||
expect(createdZoneDateTime.day).toBe(7);
|
||||
});
|
||||
|
||||
test("PlainDateTime instance argument", () => {
|
||||
const timeZone = "UTC";
|
||||
const calendar = "gregory";
|
||||
const plainDateTime = new Temporal.PlainDateTime(
|
||||
2021,
|
||||
11,
|
||||
7,
|
||||
0,
|
||||
20,
|
||||
5,
|
||||
100,
|
||||
200,
|
||||
300,
|
||||
calendar
|
||||
);
|
||||
plainDateTime.timeZone = timeZone;
|
||||
const createdZoneDateTime = Temporal.ZonedDateTime.from(plainDateTime);
|
||||
|
||||
expect(createdZoneDateTime).toBeInstanceOf(Temporal.ZonedDateTime);
|
||||
expect(createdZoneDateTime.timeZoneId).toBe(timeZone);
|
||||
expect(createdZoneDateTime.calendarId).toBe(calendar);
|
||||
expect(createdZoneDateTime.year).toBe(2021);
|
||||
expect(createdZoneDateTime.month).toBe(11);
|
||||
expect(createdZoneDateTime.day).toBe(7);
|
||||
expect(createdZoneDateTime.hour).toBe(0);
|
||||
expect(createdZoneDateTime.minute).toBe(20);
|
||||
expect(createdZoneDateTime.second).toBe(5);
|
||||
expect(createdZoneDateTime.millisecond).toBe(100);
|
||||
expect(createdZoneDateTime.microsecond).toBe(200);
|
||||
expect(createdZoneDateTime.nanosecond).toBe(300);
|
||||
});
|
||||
|
||||
test("ZonedDateTime-like argument", () => {
|
||||
const timeZone = "UTC";
|
||||
const calendar = "gregory";
|
||||
const zdtLike = {
|
||||
timeZone,
|
||||
calendar,
|
||||
year: 2021,
|
||||
month: 11,
|
||||
day: 7,
|
||||
hour: 0,
|
||||
minute: 20,
|
||||
second: 5,
|
||||
millisecond: 100,
|
||||
microsecond: 200,
|
||||
nanosecond: 300,
|
||||
};
|
||||
const createdZoneDateTime = Temporal.ZonedDateTime.from(zdtLike);
|
||||
|
||||
expect(createdZoneDateTime).toBeInstanceOf(Temporal.ZonedDateTime);
|
||||
expect(createdZoneDateTime.timeZoneId).toBe(timeZone);
|
||||
expect(createdZoneDateTime.calendarId).toBe(calendar);
|
||||
expect(createdZoneDateTime.year).toBe(2021);
|
||||
expect(createdZoneDateTime.month).toBe(11);
|
||||
expect(createdZoneDateTime.day).toBe(7);
|
||||
expect(createdZoneDateTime.hour).toBe(0);
|
||||
expect(createdZoneDateTime.minute).toBe(20);
|
||||
expect(createdZoneDateTime.second).toBe(5);
|
||||
expect(createdZoneDateTime.millisecond).toBe(100);
|
||||
expect(createdZoneDateTime.microsecond).toBe(200);
|
||||
expect(createdZoneDateTime.nanosecond).toBe(300);
|
||||
});
|
||||
|
||||
test("from string", () => {
|
||||
const zonedDateTime = Temporal.ZonedDateTime.from(
|
||||
"2021-11-07T00:20:05.100200300+00:00[UTC][u-ca=iso8601]"
|
||||
);
|
||||
|
||||
expect(zonedDateTime).toBeInstanceOf(Temporal.ZonedDateTime);
|
||||
expect(zonedDateTime.timeZoneId).toBe("UTC");
|
||||
expect(zonedDateTime.calendarId).toBe("iso8601");
|
||||
expect(zonedDateTime.year).toBe(2021);
|
||||
expect(zonedDateTime.month).toBe(11);
|
||||
expect(zonedDateTime.day).toBe(7);
|
||||
expect(zonedDateTime.hour).toBe(0);
|
||||
expect(zonedDateTime.minute).toBe(20);
|
||||
expect(zonedDateTime.second).toBe(5);
|
||||
expect(zonedDateTime.millisecond).toBe(100);
|
||||
expect(zonedDateTime.microsecond).toBe(200);
|
||||
expect(zonedDateTime.nanosecond).toBe(300);
|
||||
expect(zonedDateTime.offset).toBe("+00:00");
|
||||
expect(zonedDateTime.offsetNanoseconds).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("requires timeZone property", () => {
|
||||
expect(() => {
|
||||
Temporal.ZonedDateTime.from({});
|
||||
}).toThrowWithMessage(TypeError, "Required property timeZone is missing or undefined");
|
||||
});
|
||||
|
||||
test("invalid zoned date time string", () => {
|
||||
expect(() => {
|
||||
Temporal.ZonedDateTime.from("foo");
|
||||
}).toThrowWithMessage(RangeError, "Invalid ISO date time");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,39 @@
|
|||
describe("errors", () => {
|
||||
test("called without new", () => {
|
||||
expect(() => {
|
||||
Temporal.ZonedDateTime();
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"Temporal.ZonedDateTime constructor must be called with 'new'"
|
||||
);
|
||||
});
|
||||
|
||||
test("out-of-range epoch nanoseconds value", () => {
|
||||
expect(() => {
|
||||
new Temporal.ZonedDateTime(8_640_000_000_000_000_000_001n);
|
||||
}).toThrowWithMessage(
|
||||
RangeError,
|
||||
"Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
|
||||
);
|
||||
expect(() => {
|
||||
new Temporal.ZonedDateTime(-8_640_000_000_000_000_000_001n);
|
||||
}).toThrowWithMessage(
|
||||
RangeError,
|
||||
"Invalid epoch nanoseconds value, must be in range -86400 * 10^17 to 86400 * 10^17"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("length is 2", () => {
|
||||
expect(Temporal.ZonedDateTime).toHaveLength(2);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
expect(typeof zonedDateTime).toBe("object");
|
||||
expect(zonedDateTime).toBeInstanceOf(Temporal.ZonedDateTime);
|
||||
expect(Object.getPrototypeOf(zonedDateTime)).toBe(Temporal.ZonedDateTime.prototype);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
describe("correct behavior", () => {
|
||||
test("calendarId basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const calendar = "gregory";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(0n, timeZone, calendar);
|
||||
expect(zonedDateTime.calendarId).toBe("gregory");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "calendarId", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.day).toBe(6);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "day", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.dayOfWeek).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "dayOfWeek", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.dayOfYear).toBe(187);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "dayOfYear", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.daysInMonth).toBe(31);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "daysInMonth", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.daysInWeek).toBe(7);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "daysInWeek", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.daysInYear).toBe(365);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "daysInYear", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.epochMilliseconds).toBe(1625614921000);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "epochMilliseconds", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.epochNanoseconds).toBe(1625614921000000000n);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "epochNanoseconds", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.era).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "era", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.eraYear).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "eraYear", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.hour).toBe(23);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "hour", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.hoursInDay).toBe(24);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "hoursInDay", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.inLeapYear).toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "inLeapYear", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(123000n, timeZone);
|
||||
expect(zonedDateTime.microsecond).toBe(123);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "microsecond", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(123000000n, timeZone);
|
||||
expect(zonedDateTime.millisecond).toBe(123);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "millisecond", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.minute).toBe(42);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "minute", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.month).toBe(7);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "month", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.monthCode).toBe("M07");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "monthCode", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.monthsInYear).toBe(12);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "monthsInYear", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(123n, timeZone);
|
||||
expect(zonedDateTime.nanosecond).toBe(123);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "nanosecond", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
expect(zonedDateTime.offset).toBe("+00:00");
|
||||
});
|
||||
|
||||
test("custom offset", () => {
|
||||
const timeZone = "+01:30";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
expect(zonedDateTime.offset).toBe(timeZone);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "offset", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
expect(zonedDateTime.offsetNanoseconds).toBe(0);
|
||||
});
|
||||
|
||||
test("custom offset", () => {
|
||||
const timeZone = "+01:30";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
expect(zonedDateTime.offsetNanoseconds).toBe(5400000000000);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "offsetNanoseconds", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.second).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "second", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
expect(zonedDateTime.timeZoneId).toBe(timeZone);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "timeZoneId", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,11 @@
|
|||
describe("errors", () => {
|
||||
test("throws TypeError", () => {
|
||||
const timeZone = "UTC";
|
||||
expect(() => {
|
||||
new Temporal.ZonedDateTime(0n, timeZone).valueOf();
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"Cannot convert Temporal.ZonedDateTime to a primitive value"
|
||||
);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.weekOfYear).toBe(27);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "weekOfYear", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
||||
expect(zonedDateTime.year).toBe(2021);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "year", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const timeZone = "UTC";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1672531200000000000n, timeZone);
|
||||
expect(zonedDateTime.yearOfWeek).toBe(2022);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "yearOfWeek", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue