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.

28 lines (26 loc) • 782 B
import { plainDateOf } from "../../internal/inputChecks.js"; // src/plain/parse/parseDayOfWeekFromDate.ts /** * Return the day of week (1-7) for a given ISO 8601 date string. * * - Monday=1 through Sunday=7. * - Returns null for invalid input. * * @param value ISO date string * @returns Day of week (1-7) or null on invalid input * * @example parseDayOfWeekFromDate("2024-01-01") // 1 (Monday) * @example parseDayOfWeekFromDate("2024-01-07") // 7 (Sunday) * @example parseDayOfWeekFromDate("2024-01-08") // 1 (Monday) * @example parseDayOfWeekFromDate("invalid") // null */ function parseDayOfWeekFromDate(value) { const date = plainDateOf(value); if (date === null) return null; try { return date.dayOfWeek; } catch { return null; } } export { parseDayOfWeekFromDate };