@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) • 771 B
JavaScript
import { zonedDateTimeOf } from "../../internal/zonedWallClock.js";
// src/zoned/parse/parseSecondFromZoned.ts
/**
* Return the second (0-59) from a zoned datetime string.
*
* - Returns zero-padded string for second.
* - Returns "" for invalid input.
*
* @param value ISO zoned datetime string (e.g., "2024-03-15T14:30:45.123+00:00[UTC]")
* @returns Second (00-59) or "" on invalid input
*
* @example parseSecondFromZoned("2024-03-15T14:30:45+00:00[UTC]") // "45"
* @example parseSecondFromZoned("invalid") // ""
*/
function parseSecondFromZoned(value) {
const zonedDateTime = zonedDateTimeOf(value);
if (zonedDateTime === null) return "";
try {
return zonedDateTime.second.toString().padStart(2, "0");
} catch {
return "";
}
}
export { parseSecondFromZoned };