@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
27 lines (25 loc) • 769 B
JavaScript
import { plainTimeOf } from "../../internal/inputChecks.js";
// src/plain/parse/parseMillisecondFromTime.ts
/**
* Return the millisecond (0-999) for a given ISO 8601 time string.
*
* - Returns zero-padded string for millisecond.
* - Returns "" for invalid input.
*
* @param value ISO time string
* @returns Millisecond (000-999) or "" on invalid input
*
* @example parseMillisecondFromTime("12:30:45.123") // "123"
* @example parseMillisecondFromTime("12:30:45.000") // "000"
* @example parseMillisecondFromTime("invalid") // ""
*/
function parseMillisecondFromTime(value) {
const time = plainTimeOf(value);
if (time === null) return "";
try {
return time.millisecond.toString().padStart(3, "0");
} catch {
return "";
}
}
export { parseMillisecondFromTime };