Java Day Of Year getDaysInYear(final int year)

Here you can find the source of getDaysInYear(final int year)

Description

Returns the number of days in the year

License

Open Source License

Parameter

Parameter Description
year calendar year

Return

the number of days in the year

Declaration

private static int getDaysInYear(final int year) 

Method Source Code

//package com.java2s;
/*// w w  w .  j  ava2 s. c om
 * jGnash, a personal finance application
 * Copyright (C) 2001-2015 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/>.
 */

public class Main {
    private static final int DAYS_PER_YEAR = 365;

    /**
     * Returns the number of days in the year
     *
     * @param year calendar year
     * @return the number of days in the year
     */
    private static int getDaysInYear(final int year) {
        if (isLeapYear(year)) {
            return DAYS_PER_YEAR + 1;
        }
        return DAYS_PER_YEAR;
    }

    /**
     * Determines if the supplied year is a leap year
     *
     * @param year integer based year (ex. 2000, 2011)
     * @return {@code true} if the given year is a leap year
     */
    public static boolean isLeapYear(final int year) {
        boolean isLeapYear;

        isLeapYear = year % 4 == 0;

        isLeapYear = isLeapYear && year % 100 != 0;

        return isLeapYear || year % 400 == 0;
    }
}

Related

  1. daysInPriorYears(int yr)
  2. daysInPriorYears(int yr, boolean use1904windowing)
  3. daysInYear(int yearInteger)
  4. firstdayofyear()
  5. getDayFromYear(String year)
  6. getDaysInYear(int year)
  7. getDaysInYear(int year)
  8. getDaysOfYear(int year)
  9. getEndTimeOfYear(int year)