Skip to content

Commit 1a2d79e

Browse files
committed
simplify logic to remove switch case.
1 parent 6c0a507 commit 1a2d79e

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/datetime.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,18 @@ function toISOTime(
250250
const desiredPrecision = Precision[normalizeUnit(precision)];
251251
if (desiredPrecision === undefined) throw new InvalidUnitError(precision);
252252
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;
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 = padStart(o.c.hour);
257+
if (desiredPrecision >= Precision.minute) {
258+
c += extendedGlyph + padStart(o.c.minute);
259+
}
260+
if (desiredPrecision >= Precision.second && showSeconds) {
261+
c += extendedGlyph + padStart(o.c.second);
262+
}
263+
if (desiredPrecision >= Precision.millisecond && showMilliseconds) {
264+
c += "." + padStart(o.c.millisecond, 3);
266265
}
267266

268267
if (includeOffset) {

0 commit comments

Comments
 (0)