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) • 759 B
import { plainDateTimeOf } from "../../internal/inputChecks.js"; // src/plain/parse/parseDayFromDateTime.ts /** * Return the day of month (1-31) for a given ISO 8601 datetime string. * * - Returns zero-padded string for day. * - Returns "" for invalid input. * * @param value ISO datetime string * @returns Day (01-31) or "" on invalid input * * @example parseDayFromDateTime("2024-03-15T12:30:00") // "15" * @example parseDayFromDateTime("2024-12-31T23:59:59") // "31" * @example parseDayFromDateTime("invalid") // "" */ function parseDayFromDateTime(value) { const dateTime = plainDateTimeOf(value); if (dateTime === null) return ""; try { return dateTime.day.toString().padStart(2, "0"); } catch { return ""; } } export { parseDayFromDateTime };