From 7cfa0faa7e607f484d91f17c3768223828275bd6 Mon Sep 17 00:00:00 2001 From: snowwwz Date: Thu, 3 Oct 2024 23:02:20 +0900 Subject: [PATCH] ZZZ offset for basic ISO --- src/datetime.js | 8 ++++++-- test/datetime/format.test.js | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/datetime.js b/src/datetime.js index d4b5424cf..5780c646b 100644 --- a/src/datetime.js +++ b/src/datetime.js @@ -266,12 +266,16 @@ function toISOTime( } else if (o.o < 0) { c += "-"; c += padStart(Math.trunc(-o.o / 60)); - c += ":"; + if (extended) { + c += ":"; + } c += padStart(Math.trunc(-o.o % 60)); } else { c += "+"; c += padStart(Math.trunc(o.o / 60)); - c += ":"; + if (extended) { + c += ":"; + } c += padStart(Math.trunc(o.o % 60)); } } diff --git a/test/datetime/format.test.js b/test/datetime/format.test.js index d598a38f7..ff7f7b335 100644 --- a/test/datetime/format.test.js +++ b/test/datetime/format.test.js @@ -247,6 +247,7 @@ test("DateTime#toISOTime() can omit the offset", () => { test("DateTime#toISOTime() can output the basic format", () => { expect(dt.toISOTime({ format: "basic" })).toBe("092354.123Z"); + expect(dt.setZone("America/New_York").toISOTime({ format: "basic" })).toBe("052354.123-0400"); const dt2 = dt.set({ second: 0, millisecond: 0 }); expect(dt2.toISOTime({ format: "basic", suppressMilliseconds: true })).toBe("092300Z"); expect(dt2.toISOTime({ format: "basic", suppressSeconds: true })).toBe("0923Z");