Jave set gregorian change gregorian calendar

12 Jave code examples are found related to " set gregorian change gregorian calendar". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: GregorianCalendar.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the GregorianCalendar change date. This is the point when the switch
 * from Julian dates to Gregorian dates occurred. Default is October 15,
 * 1582. Previous to this, dates will be in the Julian calendar.
 * <p>
 * To obtain a pure Julian calendar, set the change date to
 * <code>Date(Long.MAX_VALUE)</code>.  To obtain a pure Gregorian calendar,
 * set the change date to <code>Date(Long.MIN_VALUE)</code>.
 *
 * @param date the given Gregorian cutover date.
 */
public void setGregorianChange(Date date) {
    gregorianCutover = date.getTime();

    // If the cutover has an extreme value, then create a pure
    // Gregorian or pure Julian calendar by giving the cutover year and
    // JD extreme values.
    if (gregorianCutover <= MIN_MILLIS) {
        gregorianCutoverYear = cutoverJulianDay = Integer.MIN_VALUE;
    } else if (gregorianCutover >= MAX_MILLIS) {
        gregorianCutoverYear = cutoverJulianDay = Integer.MAX_VALUE;
    } else {
        // Precompute two internal variables which we use to do the actual
        // cutover computations.  These are the Julian day of the cutover
        // and the cutover year.
        cutoverJulianDay = (int) floorDivide(gregorianCutover, ONE_DAY);
        
        // Convert cutover millis to extended year
        GregorianCalendar cal = new GregorianCalendar(getTimeZone());
        cal.setTime(date);
        gregorianCutoverYear = cal.get(EXTENDED_YEAR);
    }
}
 
Example 2
Source File: GregorianCalendar.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the GregorianCalendar change date. This is the point when the switch
 * from Julian dates to Gregorian dates occurred. Default is October 15,
 * 1582. Previous to this, dates will be in the Julian calendar.
 * <p>
 * To obtain a pure Julian calendar, set the change date to
 * <code>Date(Long.MAX_VALUE)</code>.  To obtain a pure Gregorian calendar,
 * set the change date to <code>Date(Long.MIN_VALUE)</code>.
 *
 * @param date the given Gregorian cutover date.
 * @stable ICU 2.0
 */
public void setGregorianChange(Date date) {
    gregorianCutover = date.getTime();

    // If the cutover has an extreme value, then create a pure
    // Gregorian or pure Julian calendar by giving the cutover year and
    // JD extreme values.
    if (gregorianCutover <= MIN_MILLIS) {
        gregorianCutoverYear = cutoverJulianDay = Integer.MIN_VALUE;
    } else if (gregorianCutover >= MAX_MILLIS) {
        gregorianCutoverYear = cutoverJulianDay = Integer.MAX_VALUE;
    } else {
        // Precompute two internal variables which we use to do the actual
        // cutover computations.  These are the Julian day of the cutover
        // and the cutover year.
        cutoverJulianDay = (int) floorDivide(gregorianCutover, ONE_DAY);
        
        // Convert cutover millis to extended year
        GregorianCalendar cal = new GregorianCalendar(getTimeZone());
        cal.setTime(date);
        gregorianCutoverYear = cal.get(EXTENDED_YEAR);
    }
}
 
Example 3
Source File: GregorianCalendar.java    From jtransc with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the gregorian change date of this calendar.
 */
public void setGregorianChange(Date date) {
	gregorianCutover = date.getTime();
	GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
	cal.setTime(date);
	changeYear = cal.get(YEAR);
	if (cal.get(ERA) == BC) {
		changeYear = 1 - changeYear;
	}
	julianSkew = ((changeYear - 2000) / 400) + julianError()
		- ((changeYear - 2000) / 100);
	int dayOfYear = cal.get(DAY_OF_YEAR);
	if (dayOfYear < julianSkew) {
		currentYearSkew = dayOfYear - 1;
		lastYearSkew = julianSkew - dayOfYear + 1;
	} else {
		lastYearSkew = 0;
		currentYearSkew = julianSkew;
	}
}
 
Example 4
Source File: GregorianCalendar.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar julianCal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) julianCal.newCalendarDate(TimeZone.NO_TIMEZONE);
    julianCal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
Example 5
Source File: GregorianCalendar.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar julianCal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) julianCal.newCalendarDate(TimeZone.NO_TIMEZONE);
    julianCal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
Example 6
Source File: GregorianCalendar.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar julianCal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) julianCal.newCalendarDate(TimeZone.NO_TIMEZONE);
    julianCal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
Example 7
Source File: GregorianCalendar.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar julianCal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) julianCal.newCalendarDate(TimeZone.NO_TIMEZONE);
    julianCal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
Example 8
Source File: GregorianCalendar.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar julianCal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) julianCal.newCalendarDate(TimeZone.NO_TIMEZONE);
    julianCal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
Example 9
Source File: GregorianCalendar.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar julianCal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) julianCal.newCalendarDate(TimeZone.NO_TIMEZONE);
    julianCal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
Example 10
Source File: GregorianCalendar.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar jcal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) jcal.newCalendarDate(TimeZone.NO_TIMEZONE);
    jcal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
Example 11
Source File: GregorianCalendar.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar julianCal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) julianCal.newCalendarDate(TimeZone.NO_TIMEZONE);
    julianCal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}
 
Example 12
Source File: GregorianCalendar.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void setGregorianChange(long cutoverTime) {
    gregorianCutover = cutoverTime;
    gregorianCutoverDate = CalendarUtils.floorDivide(cutoverTime, ONE_DAY)
                            + EPOCH_OFFSET;

    // To provide the "pure" Julian calendar as advertised.
    // Strictly speaking, the last millisecond should be a
    // Gregorian date. However, the API doc specifies that setting
    // the cutover date to Long.MAX_VALUE will make this calendar
    // a pure Julian calendar. (See 4167995)
    if (cutoverTime == Long.MAX_VALUE) {
        gregorianCutoverDate++;
    }

    BaseCalendar.Date d = getGregorianCutoverDate();

    // Set the cutover year (in the Gregorian year numbering)
    gregorianCutoverYear = d.getYear();

    BaseCalendar julianCal = getJulianCalendarSystem();
    d = (BaseCalendar.Date) julianCal.newCalendarDate(TimeZone.NO_TIMEZONE);
    julianCal.getCalendarDateFromFixedDate(d, gregorianCutoverDate - 1);
    gregorianCutoverYearJulian = d.getNormalizedYear();

    if (time < gregorianCutover) {
        // The field values are no longer valid under the new
        // cutover date.
        setUnnormalized();
    }
}