Skip to content

parseWeekFromUtc

parseWeekFromUtc(value: string, optionsArg?: { weekStartsOn?: "monday" | "sunday"; timeZone?: string; }): number | null

Return the week number from a UTC datetime string.

  • The result is the week of the week-year, 1–53, so late-December days can be week 1 of the next year: 2024-12-31 → 1 under either numbering, and 2000-12-30 → 53 under the Sunday-first one (minimal days 1).
  • Returns null for invalid input.
ParameterTypeDescription
valuestringISO UTC datetime string (e.g., “2024-03-17T14:30:45Z”)

optionsArg

How weeks are numbered, and the time zone the value is read in

OptionTypeDefaultDescription
weekStartsOn?"monday" | "sunday""monday"The first day of the week, which sets how the week is numbered. "monday" gives the ISO 8601 week number, where week 1 holds the year’s first Thursday; "sunday" gives the UTS #35 week number with a Sunday first day and one minimal day, where week 1 holds 1 January. Any other value returns null.
timeZone?string"UTC"The time zone the wall-clock fields are read in: an IANA name, a UTC offset (a time zone identifier such as +05:30, +0530 or -08, or a stored offset ±HH:MM[:SS], what getTimeZoneOffset returns), or "local" for the system time zone. An unknown zone returns null.

Week number (1-53), or null on invalid input

import { parseWeekFromUtc } from "@northguild/gmt/utc/parse";
parseWeekFromUtc("2024-03-17T14:30:45Z") // 11
output 

utc/parse/parseWeekFromUtc.ts