Functional Weave
Code in Python

dates.quarter@1.0.0

README.md

1,042 bytes · view raw

# dates.quarter

The calendar quarter of a date (Q1 is January to March) and its quarter in a
fiscal year that starts on the 1st of any month, with the date ranges of that
fiscal year and fiscal quarter, inclusive at both ends as a report prints them.

The fiscal year is returned as its start and end dates rather than as a year
number, because there is no agreement on the number. The UK government's year
from April 2026 is "2026-27"; the US federal year from October 2026 is "FY2027",
named for the year it ends in; many companies name theirs for the year it
starts in. The dates are unambiguous, and a label is one line of caller code
in whichever house style applies.

A fiscal year always starts on the 1st of a month here. The UK personal tax
year (6 April to 5 April) does not; use dates.uk-tax-year for that.

The fiscal year end and quarter ends use the real month lengths, so a fiscal
year starting 1 March ends on 28 or 29 February as the calendar says. A fiscal
year that would run outside 0001-01-01 to 9999-12-31 is an error.