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) • 689 B
import { Temporal } from "../../internal/temporal.js"; import { isValidDate } from "../validate/isValidDate.js"; // src/plain/parse/parseDayFromDate.ts /** * Return the day of month (1-31) for a given ISO 8601 date string. * * - Returns zero-padded string for day. * - Returns "" for invalid input. * * @param value ISO date string * @returns Day (01-31) or "" on invalid input * * @example parseDayFromDate("2024-03-15") // "15" * @example parseDayFromDate("invalid") // "" */ function parseDayFromDate(value) { if (!isValidDate(value)) return ""; try { return Temporal.PlainDate.from(value).day.toString().padStart(2, "0"); } catch { return ""; } } export { parseDayFromDate };