Skip to content

Commit 6c0a507

Browse files
committed
fix logic to pass tests
1 parent c9b1ffe commit 6c0a507

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/datetime.js

+15-14
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,22 @@ function toISOTime(
247247
extendedZone,
248248
precision
249249
) {
250-
let desiredPrecision = Precision[normalizeUnit(precision)];
250+
const desiredPrecision = Precision[normalizeUnit(precision)];
251251
if (desiredPrecision === undefined) throw new InvalidUnitError(precision);
252-
253-
switch (true) {
254-
case desiredPrecision >= Precision.hour:
255-
c += padStart(o.c.hour);
256-
case desiredPrecision >= Precision.minute:
257-
const extendedGlyph = extended ? ":" : "";
258-
c += extendedGlyph + padStart(o.c.minute);
259-
case desiredPrecision >= Precision.second:
260-
if (suppressSeconds && o.c.millisecond === 0 && o.c.second === 0) break;
261-
c += extendedGlyph + padStart(o.c.second);
262-
case desiredPrecision >= Precision.millisecond:
263-
if (suppressMilliseconds && o.c.millisecond === 0) break;
264-
c += "." + padStart(o.c.millisecond, 3);
252+
const extendedGlyph = extended ? ":" : "";
253+
const showSeconds = !suppressSeconds || o.c.millisecond !== 0 || o.c.second !== 0;
254+
const showMilliseconds = showSeconds && (!suppressMilliseconds || o.c.millisecond !== 0);
255+
256+
let c = new String();
257+
switch (desiredPrecision) {
258+
case Precision.millisecond:
259+
c = showMilliseconds ? "." + padStart(o.c.millisecond, 3) : c;
260+
case Precision.second:
261+
c = showSeconds ? extendedGlyph + padStart(o.c.second) + c : c;
262+
case Precision.minute:
263+
c = extendedGlyph + padStart(o.c.minute) + c;
264+
case Precision.hour:
265+
c = padStart(o.c.hour) + c;
265266
}
266267

267268
if (includeOffset) {

0 commit comments

Comments
 (0)