IsoFields Quarter Bucketing

Bucket a date into fiscal quarters with IsoFields: QUARTER_OF_YEAR labels the quarter and DAY_OF_QUARTER reconstructs its first and last day.

JavaData Integrity

Code

snippet
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.temporal.IsoFields;

public class QuarterBucket {

    public static void main(String[] args) {
        LocalDate close = LocalDate.of(2026, 11, 20);

        int quarter = close.get(IsoFields.QUARTER_OF_YEAR);      // 1..4
        int dayOfQuarter = close.get(IsoFields.DAY_OF_QUARTER);  // 1..92
        LocalDate quarterStart = close.with(IsoFields.DAY_OF_QUARTER, 1);
        LocalDate quarterEnd = quarterStart.plusMonths(3).minusDays(1);

        System.out.println("quarter: " + quarter);
        System.out.println("day of quarter: " + dayOfQuarter);
        System.out.println("range: " + quarterStart + " .. " + quarterEnd);

        // 财报口径:季度标签与该季度结束月份
        YearMonth quarterEndMonth = YearMonth.from(quarterEnd);
        System.out.println("label: Q" + quarter + "/" + close.getYear()
                + " end " + quarterEndMonth);
    }
}

How it works

Structurally, expect the class QuarterBucket and the function main and nothing else.

Applying it

Entry signature: public static void main(String[] args)

The file announces its steps in the output: quarter:, day of quarter:, range:.

Statements that matter

int dayOfQuarter = close.get(IsoFields.DAY_OF_QUARTER);  // 1..92
LocalDate quarterStart = close.with(IsoFields.DAY_OF_QUARTER, 1);
LocalDate quarterEnd = quarterStart.plusMonths(3).minusDays(1);
YearMonth quarterEndMonth = YearMonth.from(quarterEnd);

Interactive Tools for This Topic

FAQ

What does IsoFields Quarter Bucketing print when run?
Execute the whole file; each printed line is prefixed with a label like `quarter:`, `day of quarter:`, `range:`.