UNPKG

@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.

26 lines (24 loc) • 872 B
import { zonedDateTimeFrom } from "../../internal/zonedWallClock.js"; import { isValidZonedDateTime } from "../validate/isValidZonedDateTime.js"; // src/zoned/parse/parseMillisecondFromZoned.ts /** * Return the millisecond (0-999) from a zoned datetime string. * * - Returns zero-padded string for millisecond. * - Returns "" for invalid input. * * @param value ISO zoned datetime string (e.g., "2024-03-15T14:30:45.123+00:00[UTC]") * @returns Millisecond (000-999) or "" on invalid input * * @example parseMillisecondFromZoned("2024-03-15T14:30:45.123+00:00[UTC]") // "123" * @example parseMillisecondFromZoned("invalid") // "" */ function parseMillisecondFromZoned(value) { if (!isValidZonedDateTime(value)) return ""; try { return zonedDateTimeFrom(value).millisecond.toString().padStart(3, "0"); } catch { return ""; } } export { parseMillisecondFromZoned };