Dev Helpers

React / Calendar arithmetic

Quarter identifier

Dev Helpers · August 25, 2025

JavaScript months are zero-based, while quarter labels start at one. Derive the quarter from the calendar convention your users expect.

Worked example

// components/QuarterIdentifier.tsx

export default function QuarterIdentifier({
  day = "2028-02-29",
}: { day?: string } = {}) {
  const d = new Date(day + "T00:00Z");
  return (
    <time dateTime={day}>
      Q{1 + Math.floor(d.getUTCMonth() / 3)} {d.getUTCFullYear()}
    </time>
  );
}

Implementation notes

Fiscal quarters can start in another month. Put the fiscal offset in one function rather than scattering adjustments across components.

Try it yourself

Test March 31 and April 1.

Open the React example →

Editorial date August 25, 2025 · Published December 6, 2026

Related articles

Percentage meter

A percentage meter needs both a bounded visual fill and a meaningful textual value. Handle a zero denominator before dividing.

Vertical typesetting sample

Vertical typesetting changes the reading direction and available inline space. Treat the sample text as content so it remains selectable and accessible.

Square cover crop

A square image crop gives a card grid consistent geometry. The crop anchor determines whether the most important part of a photo survives.