Skip to content

Commit 4cc03e5

Browse files
authored
Fix offset formatting in ISO strings for format=basic (#1660)
1 parent 1337c7b commit 4cc03e5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/datetime.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,16 @@ function toISOTime(
280280
} else if (o.o < 0) {
281281
c += "-";
282282
c += padStart(Math.trunc(-o.o / 60));
283-
c += ":";
283+
if (extended) {
284+
c += ":";
285+
}
284286
c += padStart(Math.trunc(-o.o % 60));
285287
} else {
286288
c += "+";
287289
c += padStart(Math.trunc(o.o / 60));
288-
c += ":";
290+
if (extended) {
291+
c += ":";
292+
}
289293
c += padStart(Math.trunc(o.o % 60));
290294
}
291295
}

test/datetime/format.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ test("DateTime#toISOTime() can omit the offset", () => {
280280

281281
test("DateTime#toISOTime() can output the basic format", () => {
282282
expect(dt.toISOTime({ format: "basic" })).toBe("092354.123Z");
283+
expect(dt.setZone("America/New_York").toISOTime({ format: "basic" })).toBe("052354.123-0400");
283284
const dt2 = dt.set({ second: 0, millisecond: 0 });
284285
expect(dt2.toISOTime({ format: "basic", suppressMilliseconds: true })).toBe("092300Z");
285286
expect(dt2.toISOTime({ format: "basic", suppressSeconds: true })).toBe("0923Z");

0 commit comments

Comments
 (0)