Skip to content

getQuarter

getQuarter(value: string, optionsArg?: { fiscalYearStartMonth?: number; }): { year: number; quarter: number; } | null

Return 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 year is the calendar year.
  • Labelling a fiscal year by the calendar year it starts in matches the NRF retail convention getFiscalPeriod uses. 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 to year.
  • 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, including a fiscalYearStartMonth that is not an integer from 1 to 12.
ParameterTypeDescription
valuestringzoneless ISO 8601 date or datetime string (e.g. “2024-06-15”)

optionsArg

The month the fiscal year starts in

OptionTypeDefaultDescription
fiscalYearStartMonth?number1The 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.

{ year, quarter }, or null on invalid input

Members

MemberTypeDescription
yearnumberThe 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.
quarternumberThe quarter of that year, 1 through 4. Quarter 1 begins in the fiscalYearStartMonth month, which is January by default.
import { getQuarter } from "@northguild/gmt/calendar/calculate";
getQuarter("2024-06-15") // { year: 2024, quarter: 2 }
output 

calendar/calculate/getQuarter.ts