mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:47:35 +00:00
LibJS: Implement parsing of TemporalRelativeToString
This commit is contained in:
parent
98b876ad3f
commit
1583c7257c
12 changed files with 370 additions and 61 deletions
|
@ -3,8 +3,7 @@ describe("correct behavior", () => {
|
|||
expect(Temporal.Instant.prototype.toZonedDateTimeISO).toHaveLength(1);
|
||||
});
|
||||
|
||||
// TODO: Un-skip when ParseTemporalTimeZoneString is fully implemented
|
||||
test.skip("basic functionality", () => {
|
||||
test("basic functionality", () => {
|
||||
const instant = new Temporal.Instant(1625614921123456789n);
|
||||
const zonedDateTime = instant.toZonedDateTimeISO("UTC");
|
||||
expect(zonedDateTime.year).toBe(2021);
|
||||
|
|
|
@ -58,8 +58,7 @@ describe("correct behavior", () => {
|
|||
expect(zonedDateTime.timeZone).toBe(timeZone);
|
||||
});
|
||||
|
||||
// TODO: Enable when parse_temporal_time_zone_string() is fully implemented
|
||||
test.skip("basic functionality - time zone identifier", () => {
|
||||
test("basic functionality - time zone identifier", () => {
|
||||
// 4. in the spec
|
||||
const plainDate = new Temporal.PlainDate(2021, 7, 6);
|
||||
const zonedDateTime = plainDate.toZonedDateTime("UTC");
|
||||
|
|
|
@ -95,8 +95,7 @@ describe("correct behavior", () => {
|
|||
expect(plainDateTime.nanosecond).toBe(999);
|
||||
});
|
||||
|
||||
// Un-skip once ParseISODateTime & ParseTemporalDateString are implemented
|
||||
test.skip("PlainDateTime string argument", () => {
|
||||
test("PlainDateTime string argument", () => {
|
||||
const plainDateTime = Temporal.PlainDateTime.from("2021-07-06T23:42:01Z");
|
||||
expect(plainDateTime.year).toBe(2021);
|
||||
expect(plainDateTime.month).toBe(7);
|
||||
|
|
|
@ -41,8 +41,7 @@ describe("correct behavior", () => {
|
|||
expect(plainMonthDay.day).toBe(6);
|
||||
});
|
||||
|
||||
// Un-skip once ParseISODateTime, ToTemporalMonthDay & ParseTemporalMonthDayString are fully implemented
|
||||
test.skip("from date time string", () => {
|
||||
test("from date time string", () => {
|
||||
const plainMonthDay = Temporal.PlainMonthDay.from("2021-07-06T23:42:01Z");
|
||||
expect(plainMonthDay.monthCode).toBe("M07");
|
||||
expect(plainMonthDay.day).toBe(6);
|
||||
|
|
|
@ -37,8 +37,7 @@ describe("correct behavior", () => {
|
|||
expect(createdPlainTime.nanosecond).toBe(0);
|
||||
});
|
||||
|
||||
// Un-skip once ParseISODateTime & ParseTemporalTimeString are implemented
|
||||
test.skip("PlainTime string argument", () => {
|
||||
test("PlainTime string argument", () => {
|
||||
const createdPlainTime = Temporal.PlainTime.from("2021-08-27T18:44:11Z");
|
||||
expect(createdPlainTime.hour).toBe(18);
|
||||
expect(createdPlainTime.minute).toBe(44);
|
||||
|
|
|
@ -62,8 +62,7 @@ describe("correct behavior", () => {
|
|||
expect(plainYearMonth.monthCode).toBe("M07");
|
||||
});
|
||||
|
||||
// Un-skip once ParseISODateTime & ParseTemporalYearMonthString are fully implemented
|
||||
test.skip("from date time string", () => {
|
||||
test("from date time string", () => {
|
||||
const plainYearMonth = Temporal.PlainYearMonth.from("2021-07-06T23:42:01Z");
|
||||
expect(plainYearMonth.year).toBe(2021);
|
||||
expect(plainYearMonth.month).toBe(7);
|
||||
|
|
|
@ -96,7 +96,7 @@ describe("correct behavior", () => {
|
|||
});
|
||||
|
||||
// FIXME: Enable when parse_iso_date_time is implemented.
|
||||
test.skip("from string", () => {
|
||||
test("from string", () => {
|
||||
const zonedDateTime = Temporal.ZonedDateTime.from(
|
||||
"2021-11-07T00:20:05.100200300+00:00[UTC][u-ca=iso8601]"
|
||||
);
|
||||
|
@ -106,17 +106,17 @@ describe("correct behavior", () => {
|
|||
expect(zonedDateTime.timeZone.id).toBe("UTC");
|
||||
expect(zonedDateTime.calendar).toBeInstanceOf(Temporal.Calendar);
|
||||
expect(zonedDateTime.calendar.id).toBe("iso8601");
|
||||
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);
|
||||
expect(createdZoneDateTime.offset).toBe("+00:00");
|
||||
expect(createdZoneDateTime.offsetNanoseconds).toBe(0);
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -13,8 +13,7 @@ describe("correct behavior", () => {
|
|||
expect(withTimeZoneZonedDateTime.timeZone).toBe(timeZone);
|
||||
});
|
||||
|
||||
// FIXME: Enable this when time zone string parsing is implemented.
|
||||
test.skip("from time zone string", () => {
|
||||
test("from time zone string", () => {
|
||||
const object = {};
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1n, object);
|
||||
expect(zonedDateTime.timeZone).toBe(object);
|
||||
|
@ -32,13 +31,11 @@ describe("errors", () => {
|
|||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
|
||||
// FIXME: Enable this when time zone string parsing is implemented.
|
||||
test.skip("from invalid time zone string", () => {
|
||||
test("from invalid time zone string", () => {
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1n, {});
|
||||
|
||||
// FIXME: Use "toThrowWithMessage" once this has an error message.
|
||||
expect(() => {
|
||||
zonedDateTime.withTimeZone("UTCfoobar");
|
||||
}).toThrow(RangeError);
|
||||
}).toThrowWithMessage(RangeError, "Invalid time zone string 'UTCfoobar'");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue