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.

29 lines (27 loc) • 971 B
import { isOptionsArgument } from "../../internal/isObject.js"; import { utcWallClock } from "../../internal/utcWallClock.js"; // src/utc/parse/parseMinuteFromUtc.ts /** * Return the minute (0-59) from a UTC datetime string. * * - Returns zero-padded string for minute. * - Returns "" for invalid input. * * @param value ISO UTC datetime string (e.g., "2024-03-17T14:30:45Z") * @param options The time zone the value is read in * @returns Minute (00-59) or "" on invalid input * * @example parseMinuteFromUtc("2024-03-17T14:30:45Z") // "30" * @example parseMinuteFromUtc("2024-03-17T02:30:45Z", { timeZone: "Asia/Kolkata" }) // "00" * @example parseMinuteFromUtc("invalid") // "" */ function parseMinuteFromUtc(value, options) { try { if (!isOptionsArgument(options)) return ""; const dateTime = utcWallClock(value, options); return dateTime === null ? "" : dateTime.minute.toString().padStart(2, "0"); } catch { return ""; } } export { parseMinuteFromUtc };