@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) • 831 B
JavaScript
import { zonedDateTimeOf } from "../../internal/zonedWallClock.js";
// src/zoned/parse/parseDayOfWeekFromZoned.ts
/**
* Return the day of the week (1-7, Monday-Sunday) from a zoned datetime string.
*
* - Returns number 1-7 for valid input.
* - Monday=1 through Sunday=7.
* - Returns null for invalid input.
*
* @param value ISO zoned datetime string (e.g., "2024-03-15T14:30:45.123+00:00[UTC]")
* @returns Day of week (1-7) or null on invalid input
*
* @example parseDayOfWeekFromZoned("2024-03-15T14:30:45+00:00[UTC]") // 5 (Friday)
* @example parseDayOfWeekFromZoned("invalid") // null
*/
function parseDayOfWeekFromZoned(value) {
const zonedDateTime = zonedDateTimeOf(value);
if (zonedDateTime === null) return null;
try {
return zonedDateTime.dayOfWeek;
} catch {
return null;
}
}
export { parseDayOfWeekFromZoned };