Computes a date's calendar quarter and its fiscal quarter and fiscal year for a given fiscal-year start month.
Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.
Try it
Inputs
date (string, required) : ISO 8601 date, YYYY-MM-DD
fiscal_year_start_month (integer, required) min 1 max 12 : Month (1-12) the fiscal year starts in; 1 means the fiscal year equals the calendar year; 10 matches the US federal fiscal year
Outputs
calendar_quarter: Q1-Q4 of the calendar year
fiscal_quarter: Q1-Q4 of the fiscal year
fiscal_year: The fiscal year label, named for the calendar year in which the fiscal year ends (matching the US federal convention)
Steps
Parse the date as a proleptic Gregorian civil date.
calendar_quarter = floor((month - 1) / 3) + 1.
If fiscal_year_start_month is 1, the fiscal year always equals the calendar year (a fiscal year that starts and ends within the same January-December span cannot be named for a different year).
Otherwise: if the date's month is on or after fiscal_year_start_month, the fiscal year is named for the NEXT calendar year (the fiscal year that starts this year and ends next year); if the month is before fiscal_year_start_month, it is named for the current calendar year (the fiscal year already in progress, started the prior calendar year).