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.

27 lines (25 loc) • 780 B
import { plainDateTimeOf } from "../../internal/inputChecks.js"; // src/plain/parse/parseSecondFromDateTime.ts /** * Return the second (0-59) for a given ISO 8601 datetime string. * * - Returns zero-padded string for second. * - Returns "" for invalid input. * * @param value ISO datetime string * @returns Second (00-59) or "" on invalid input * * @example parseSecondFromDateTime("2024-03-15T14:30:45") // "45" * @example parseSecondFromDateTime("2024-03-15T14:30:00") // "00" * @example parseSecondFromDateTime("invalid") // "" */ function parseSecondFromDateTime(value) { const dateTime = plainDateTimeOf(value); if (dateTime === null) return ""; try { return dateTime.second.toString().padStart(2, "0"); } catch { return ""; } } export { parseSecondFromDateTime };