getOrdinalDate
Signature
Section titled “Signature”getOrdinalDate(value: string): { year: number; dayOfYear: number; } | nullReturn 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. valuemust be zoneless — an ISO date or datetime, asisValidIsoDateLikeaccepts. SeegetIsoWeekDatefor why a moment is not accepted here.- Returns null on invalid input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | zoneless ISO 8601 date or datetime string (e.g. “2024-06-15”) |
Returns
Section titled “Returns”{ year, dayOfYear }, or null on invalid input
Members
| Member | Type | Description |
|---|---|---|
year | number | The calendar year of the date. It is not the ISO 8601 week-numbering year, so it always matches the year written in value. |
dayOfYear | number | The 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. |
Examples
Section titled “Examples”import { getOrdinalDate } from "@northguild/gmt/calendar/calculate";
getOrdinalDate("2024-01-01") // { year: 2024, dayOfYear: 1 }