Skip to content

getOrdinalDate

getOrdinalDate(value: string): { year: number; dayOfYear: number; } | null

Return the ISO 8601 ordinal date — calendar year and day of year — for value.

  • Unlike getIsoWeekDate, whose year is the week-numbering year, an ordinal date never disagrees with the calendar year it is written beside.
  • value must be zoneless — an ISO date or datetime, as isValidIsoDateLike accepts. See getIsoWeekDate for why a moment is not accepted here.
  • Returns null on invalid input.
ParameterTypeDescription
valuestringzoneless ISO 8601 date or datetime string (e.g. “2024-06-15”)

{ year, dayOfYear }, or null on invalid input

Members

MemberTypeDescription
yearnumberThe calendar year of the date. It is not the ISO 8601 week-numbering year, so it always matches the year written in value.
dayOfYearnumberThe 1-based day of that year, the ISO 8601 ordinal day: 1 is January 1, and December 31 is 365, or 366 in a leap year.
import { getOrdinalDate } from "@northguild/gmt/calendar/calculate";
getOrdinalDate("2024-01-01") // { year: 2024, dayOfYear: 1 }
output 

calendar/calculate/getOrdinalDate.ts