Java LocalDate Calculate getQuarterBounds(final LocalDate date)

Here you can find the source of getQuarterBounds(final LocalDate date)

Description

Returns an array of quarter bound dates of the year based on a specified date.

License

Open Source License

Parameter

Parameter Description
date the base date to work from

Return

The array of quarter bound dates

Declaration

private static LocalDate[] getQuarterBounds(final LocalDate date) 

Method Source Code

//package com.java2s;
/*//from  w  w  w .  j ava2s . c o m
 * jGnash, a personal finance application
 * Copyright (C) 2001-2019 Craig Cavanaugh
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.time.LocalDate;

import java.time.Month;

import java.time.temporal.TemporalAdjusters;

import java.util.Objects;

public class Main {
    private static final int DAYS_PER_WEEK = 7;

    /**
     * Returns an array of quarter bound dates of the year based on a specified
     * date. The order is q1s, q1e, q2s, q2e, q3s, q3e, q4s, q4e.
     *
     * @param date the base date to work from
     * @return The array of quarter bound dates
     */
    private static LocalDate[] getQuarterBounds(final LocalDate date) {
        Objects.requireNonNull(date);

        final LocalDate[] bounds = new LocalDate[8];

        bounds[0] = date.with(TemporalAdjusters.firstDayOfYear());
        bounds[1] = date.withMonth(Month.MARCH.getValue()).with(TemporalAdjusters.lastDayOfMonth());
        bounds[2] = date.withMonth(Month.APRIL.getValue()).with(TemporalAdjusters.firstDayOfMonth());
        bounds[3] = date.withMonth(Month.JUNE.getValue()).with(TemporalAdjusters.lastDayOfMonth());
        bounds[4] = date.withMonth(Month.JULY.getValue()).with(TemporalAdjusters.firstDayOfMonth());
        bounds[5] = date.withMonth(Month.SEPTEMBER.getValue()).with(TemporalAdjusters.lastDayOfMonth());
        bounds[6] = date.withMonth(Month.OCTOBER.getValue()).with(TemporalAdjusters.firstDayOfMonth());
        bounds[DAYS_PER_WEEK] = date.with(TemporalAdjusters.lastDayOfYear());

        return bounds;
    }
}

Related

  1. getLastDayOfTheQuarter(final LocalDate date)
  2. getLocalDateBydayAndWeek(LocalDate localDate, int weekNumber, int dayNumber)
  3. getLrsLocalDate(String lbdcDate)
  4. getMax(@Nonnull final LocalDate aDate1, @Nonnull final LocalDate aDate2)
  5. getNextNoWeekedDay(LocalDate today)
  6. getTimeDifferenceInDays(LocalDate to)
  7. getTodayAsLocalDate()
  8. getWeekOfTheYear(final LocalDate dateOfYear)
  9. getYearMonth(LocalDate localDate)