diff options
author | Linus Groh <mail@linusgroh.de> | 2021-11-02 17:47:23 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-11-02 18:40:37 +0100 |
commit | e27bb940383ae912bd72d66a5a08344409ee6dac (patch) | |
tree | 5f6dc09c261027f8348e21c4c66fa4e896b9c41b /Userland/Libraries/LibJS/Tests | |
parent | fc411695c76554cf1907121a851441a574498c49 (diff) | |
download | serenity-e27bb940383ae912bd72d66a5a08344409ee6dac.zip |
LibJS: Implement Temporal.PlainDate.prototype.toZonedDateTime()
Diffstat (limited to 'Userland/Libraries/LibJS/Tests')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainDate/PlainDate.prototype.toZonedDateTime.js | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainDate/PlainDate.prototype.toZonedDateTime.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainDate/PlainDate.prototype.toZonedDateTime.js new file mode 100644 index 0000000000..f6c57d8908 --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/PlainDate/PlainDate.prototype.toZonedDateTime.js @@ -0,0 +1,86 @@ +describe("correct behavior", () => { + test("length is 1", () => { + expect(Temporal.PlainDate.prototype.toZonedDateTime).toHaveLength(1); + }); + + test("basic functionality - time zone", () => { + // 3.b. in the spec + const plainDate = new Temporal.PlainDate(2021, 7, 6); + const timeZone = new Temporal.TimeZone("UTC"); + const zonedDateTime = plainDate.toZonedDateTime(timeZone); + expect(zonedDateTime.year).toBe(2021); + expect(zonedDateTime.month).toBe(7); + expect(zonedDateTime.day).toBe(6); + expect(zonedDateTime.hour).toBe(0); + expect(zonedDateTime.minute).toBe(0); + expect(zonedDateTime.second).toBe(0); + expect(zonedDateTime.millisecond).toBe(0); + expect(zonedDateTime.microsecond).toBe(0); + expect(zonedDateTime.nanosecond).toBe(0); + expect(zonedDateTime.calendar).toBe(plainDate.calendar); + expect(zonedDateTime.timeZone).toBe(timeZone); + }); + + test("basic functionality - time zone like object", () => { + // 3.c. in the spec + const plainDate = new Temporal.PlainDate(2021, 7, 6); + const timeZone = new Temporal.TimeZone("UTC"); + const zonedDateTime = plainDate.toZonedDateTime({ timeZone }); + expect(zonedDateTime.year).toBe(2021); + expect(zonedDateTime.month).toBe(7); + expect(zonedDateTime.day).toBe(6); + expect(zonedDateTime.hour).toBe(0); + expect(zonedDateTime.minute).toBe(0); + expect(zonedDateTime.second).toBe(0); + expect(zonedDateTime.millisecond).toBe(0); + expect(zonedDateTime.microsecond).toBe(0); + expect(zonedDateTime.nanosecond).toBe(0); + expect(zonedDateTime.calendar).toBe(plainDate.calendar); + expect(zonedDateTime.timeZone).toBe(timeZone); + }); + + test("basic functionality - time zone like object and plain time", () => { + // 3.c. in the spec + const plainDate = new Temporal.PlainDate(2021, 7, 6); + const plainTime = new Temporal.PlainTime(18, 14, 47, 123, 456, 789); + const timeZone = new Temporal.TimeZone("UTC"); + const zonedDateTime = plainDate.toZonedDateTime({ timeZone, plainTime }); + expect(zonedDateTime.year).toBe(2021); + expect(zonedDateTime.month).toBe(7); + expect(zonedDateTime.day).toBe(6); + expect(zonedDateTime.hour).toBe(18); + expect(zonedDateTime.minute).toBe(14); + expect(zonedDateTime.second).toBe(47); + expect(zonedDateTime.millisecond).toBe(123); + expect(zonedDateTime.microsecond).toBe(456); + expect(zonedDateTime.nanosecond).toBe(789); + expect(zonedDateTime.calendar).toBe(plainDate.calendar); + expect(zonedDateTime.timeZone).toBe(timeZone); + }); + + // TODO: Enable when parse_temporal_time_zone_string() is fully implemented + test.skip("basic functionality - time zone identifier", () => { + // 4. in the spec + const plainDate = new Temporal.PlainDate(2021, 7, 6); + const zonedDateTime = plainDate.toZonedDateTime("UTC"); + expect(zonedDateTime.year).toBe(2021); + expect(zonedDateTime.month).toBe(7); + expect(zonedDateTime.day).toBe(6); + expect(zonedDateTime.hour).toBe(0); + expect(zonedDateTime.minute).toBe(0); + expect(zonedDateTime.second).toBe(0); + expect(zonedDateTime.millisecond).toBe(0); + expect(zonedDateTime.microsecond).toBe(0); + expect(zonedDateTime.nanosecond).toBe(0); + expect(zonedDateTime.calendar).toBe(plainDate.calendar); + expect(zonedDateTime.timeZone.id).toBe("UTC"); + }); +}); + +describe("errors", () => { + test("this value must be a Temporal.PlainDate object", () => { + expect(() => { + Temporal.PlainDate.prototype.toZonedDateTime.call("foo"); + }).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainDate"); + }); +}); |