Android Gregorian Date Create isGregorianDate(int year, int month, double day)

Here you can find the source of isGregorianDate(int year, int month, double day)

Description

Calculates whether the given date is Gregorian, i.e.

License

Open Source License

Parameter

Parameter Description
year year value
month month of the year (first month is 1)
day day of the month including fraction of hours, minutes, seconds and milliseconds

Return

true if date is after the beginning of the Gregorian calendar, false otherwise

Declaration

public static boolean isGregorianDate(int year, int month, double day) 

Method Source Code

//package com.java2s;
/*/*from   w  w w  .jav  a2 s.com*/
 * Copyright (C) 2011-2012 Inaki Ortiz de Landaluce Saiz
 * 
 * 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 Lesser General Public 
 * License along with this program. If not, see 
 * <http://www.gnu.org/licenses/>
 */

import java.util.Calendar;

import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Main {
    /**
     * Calculates whether the given date is Gregorian, i.e. is after 1582
     * October 15th.
     * 
     * @param year
     *            year value
     * @param month
     *            month of the year (first month is 1)
     * @param day
     *            day of the month including fraction of hours, minutes, seconds
     *            and milliseconds
     * @return true if date is after the beginning of the Gregorian calendar,
     *         false otherwise
     */
    public static boolean isGregorianDate(int year, int month, double day) {
        // start of Gregorian calendar is 15/10/1582
        Calendar gregorianZero = new GregorianCalendar(
                TimeZone.getTimeZone("GMT"));
        gregorianZero.set(Calendar.YEAR, 1582);
        gregorianZero.set(Calendar.MONTH, 9); // October
        gregorianZero.set(Calendar.DAY_OF_MONTH, 15);

        Calendar calendar = new GregorianCalendar(
                TimeZone.getTimeZone("GMT"));
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DAY_OF_MONTH, (int) day);

        return (calendar.after(gregorianZero));
    }
}

Related

  1. isValid(int year, int month, int day)
  2. getDateObj(int year, int month, int day)
  3. getCalendar()
  4. dateInts2String(int year, int month, int day)