getQuarter
Signature
Section titled “Signature”getQuarter(value: string, optionsArg?: { fiscalYearStartMonth?: number; }): { year: number; quarter: number; } | nullReturn the quarter value falls in, as a year and a quarter number.
- With no options these are the calendar quarters: Q1 is January to March, and
yearis the calendar year. - Labelling a fiscal year by the calendar year it starts in matches the NRF retail convention
getFiscalPerioduses. Organisations that label a fiscal year by the calendar year it ends in — for a fiscal year that starts in October, FY2025 begins in October 2024 — should add one toyear. valuemust be zoneless — an ISO date or datetime, asisValidIsoDateLikeaccepts. SeegetIsoWeekDatefor why a moment is not accepted here.- Returns null on invalid input, including a
fiscalYearStartMonththat is not an integer from 1 to 12.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | zoneless ISO 8601 date or datetime string (e.g. “2024-06-15”) |
Options
Section titled “Options”optionsArg
The month the fiscal year starts in
| Option | Type | Default | Description |
|---|---|---|---|
fiscalYearStartMonth? | number | 1 | The month the year starts in, 1 (January) through 12, which makes the quarters fiscal quarters. A date before it belongs to the previous fiscal year, so with 4 the date "2024-03-31" is Q4 of 2023. |
Returns
Section titled “Returns”{ year, quarter }, or null on invalid input
Members
| Member | Type | Description |
|---|---|---|
year | number | The year the quarter belongs to. With fiscalYearStartMonth set, it is the calendar year the fiscal year starts in, so a date before the start month reports the previous year. |
quarter | number | The quarter of that year, 1 through 4. Quarter 1 begins in the fiscalYearStartMonth month, which is January by default. |
Examples
Section titled “Examples”import { getQuarter } from "@northguild/gmt/calendar/calculate";
getQuarter("2024-06-15") // { year: 2024, quarter: 2 }