From 4cc03e5b71240ece26ba1424cabcf35b8a939c56 Mon Sep 17 00:00:00 2001 From: snowwwz <61674849+snowwwz@users.noreply.github.com> Date: Wed, 30 Jul 2025 06:43:28 +0900 Subject: [PATCH] Fix offset formatting in ISO strings for format=basic (#1660) --- 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 40a3f5511..7ea16cec1 100644 --- a/src/datetime.js +++ b/src/datetime.js @@ -280,12 +280,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 8d0baa3c5..20efe0fab 100644 --- a/test/datetime/format.test.js +++ b/test/datetime/format.test.js @@ -280,6 +280,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");