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) • 836 B
import { Temporal } from "../../internal/temporal.js"; import { isValidDateTime } from "../validate/isValidDateTime.js"; // src/plain/parse/parseDayOfWeekFromDateTime.ts /** * Return the day of week (1-7) for a given ISO 8601 datetime string. * * - Monday=1 through Sunday=7. * - Returns null for invalid input. * * @param value ISO datetime string * @returns Day of week (1-7) or null on invalid input * * @example parseDayOfWeekFromDateTime("2024-01-01T12:00:00") // 1 (Monday) * @example parseDayOfWeekFromDateTime("2024-01-07T00:00:00") // 7 (Sunday) * @example parseDayOfWeekFromDateTime("invalid") // null */ function parseDayOfWeekFromDateTime(value) { if (!isValidDateTime(value)) return null; try { return Temporal.PlainDateTime.from(value).dayOfWeek; } catch { return null; } } export { parseDayOfWeekFromDateTime };