Java Day Of Year daysInPriorYears(int yr, boolean use1904windowing)

Here you can find the source of daysInPriorYears(int yr, boolean use1904windowing)

Description

Return the number of days in prior years since 1900

License

Apache License

Parameter

Parameter Description
yr a year (1900 < yr < 4000)
use1904windowing a parameter

Return

days number of days in years prior to yr.

Declaration


private static int daysInPriorYears(int yr, boolean use1904windowing) 

Method Source Code

//package com.java2s;
/* ====================================================================
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License./*  ww  w .  j a v a  2s.  c o m*/
 ==================================================================== */

public class Main {
    /**
     * Return the number of days in prior years since 1900
     *
     * @return    days  number of days in years prior to yr.
     * @param     yr    a year (1900 < yr < 4000)
     * @param use1904windowing
     * @exception IllegalArgumentException if year is outside of range.
     */

    private static int daysInPriorYears(int yr, boolean use1904windowing) {
        if ((!use1904windowing && yr < 1900)
                || (use1904windowing && yr < 1900)) {
            throw new IllegalArgumentException(
                    "'year' must be 1900 or greater");
        }

        int yr1 = yr - 1;
        int leapDays = yr1 / 4 // plus julian leap days in prior years
                - yr1 / 100 // minus prior century years
                + yr1 / 400 // plus years divisible by 400
                - 460; // leap days in previous 1900 years

        return 365 * (yr - (use1904windowing ? 1904 : 1900)) + leapDays;
    }
}

Related

  1. dayOfYear(int year, int month, int date)
  2. dayOfYear(int year, int month, int day)
  3. dayOfYear(int year, int month, int day)
  4. daysInPriorYears(final int y)
  5. daysInPriorYears(int yr)
  6. daysInYear(int yearInteger)
  7. firstdayofyear()
  8. getDayFromYear(String year)
  9. getDaysInYear(final int year)