@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.
25 lines (23 loc) • 749 B
JavaScript
import { plainTimeOf } from "../../internal/inputChecks.js";
// src/plain/parse/parseMicrosecondFromTime.ts
/**
* Return the microsecond (0-999) for a given ISO 8601 time string.
*
* @param value ISO time string
* @returns Microsecond (000-999) or "" on invalid input
*
* @example parseMicrosecondFromTime("12:30:45.123") // "000"
* @example parseMicrosecondFromTime("12:30:45.123456") // "456"
* @example parseMicrosecondFromTime("12:30:45.000") // "000"
* @example parseMicrosecondFromTime("invalid") // ""
*/
function parseMicrosecondFromTime(value) {
const time = plainTimeOf(value);
if (time === null) return "";
try {
return time.microsecond.toString().padStart(3, "0");
} catch {
return "";
}
}
export { parseMicrosecondFromTime };