sun.util.calendar.BaseCalendar Java Examples

The following examples show how to use sun.util.calendar.BaseCalendar. 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. You may check out the related API usage on the sidebar.
Example #1
Source File: Date.java    From jdk8u60 with GNU General Public License v2.0 7 votes vote down vote up
/**
 * Sets the month of this date to the specified value. This
 * <tt>Date</tt> object is modified so that it represents a point
 * in time within the specified month, with the year, date, hour,
 * minute, and second the same as before, as interpreted in the
 * local time zone. If the date was October 31, for example, and
 * the month is set to June, then the new date will be treated as
 * if it were on July 1, because June has only 30 days.
 *
 * @param   month   the month value between 0-11.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(Calendar.MONTH, int month)</code>.
 */
@Deprecated
public void setMonth(int month) {
    int y = 0;
    if (month >= 12) {
        y = month / 12;
        month %= 12;
    } else if (month < 0) {
        y = CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    BaseCalendar.Date d = getCalendarDate();
    if (y != 0) {
        d.setNormalizedYear(d.getNormalizedYear() + y);
    }
    d.setMonth(month + 1); // adjust 0-based to 1-based month numbering
}
 
Example #2
Source File: GregorianCalendar.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines if the given year is a leap year. Returns <code>true</code> if
 * the given year is a leap year. To specify BC year numbers,
 * <code>1 - year number</code> must be given. For example, year BC 4 is
 * specified as -3.
 *
 * @param year the given year.
 * @return <code>true</code> if the given year is a leap year; <code>false</code> otherwise.
 */
public boolean isLeapYear(int year) {
    if ((year & 3) != 0) {
        return false;
    }

    if (year > gregorianCutoverYear) {
        return (year%100 != 0) || (year%400 == 0); // Gregorian
    }
    if (year < gregorianCutoverYearJulian) {
        return true; // Julian
    }
    boolean gregorian;
    // If the given year is the Gregorian cutover year, we need to
    // determine which calendar system to be applied to February in the year.
    if (gregorianCutoverYear == gregorianCutoverYearJulian) {
        BaseCalendar.Date d = getCalendarDate(gregorianCutoverDate); // Gregorian
        gregorian = d.getMonth() < BaseCalendar.MARCH;
    } else {
        gregorian = year == gregorianCutoverYear;
    }
    return gregorian ? (year%100 != 0) || (year%400 == 0) : true;
}
 
Example #3
Source File: GregorianCalendar.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the fixed date of the first day of the year (usually
 * January 1) before the specified date.
 *
 * @param date the date for which the first day of the year is
 * calculated. The date has to be in the cut-over year (Gregorian
 * or Julian).
 * @param fixedDate the fixed date representation of the date
 */
private long getFixedDateJan1(BaseCalendar.Date date, long fixedDate) {
    assert date.getNormalizedYear() == gregorianCutoverYear ||
        date.getNormalizedYear() == gregorianCutoverYearJulian;
    if (gregorianCutoverYear != gregorianCutoverYearJulian) {
        if (fixedDate >= gregorianCutoverDate) {
            // Dates before the cutover date don't exist
            // in the same (Gregorian) year. So, no
            // January 1 exists in the year. Use the
            // cutover date as the first day of the year.
            return gregorianCutoverDate;
        }
    }
    // January 1 of the normalized year should exist.
    BaseCalendar juliancal = getJulianCalendarSystem();
    return juliancal.getFixedDate(date.getNormalizedYear(), BaseCalendar.JANUARY, 1, null);
}
 
Example #4
Source File: GregorianCalendar.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns the fixed date of the first day of the year (usually
 * January 1) before the specified date.
 *
 * @param date the date for which the first day of the year is
 * calculated. The date has to be in the cut-over year (Gregorian
 * or Julian).
 * @param fixedDate the fixed date representation of the date
 */
private long getFixedDateJan1(BaseCalendar.Date date, long fixedDate) {
    assert date.getNormalizedYear() == gregorianCutoverYear ||
        date.getNormalizedYear() == gregorianCutoverYearJulian;
    if (gregorianCutoverYear != gregorianCutoverYearJulian) {
        if (fixedDate >= gregorianCutoverDate) {
            // Dates before the cutover date don't exist
            // in the same (Gregorian) year. So, no
            // January 1 exists in the year. Use the
            // cutover date as the first day of the year.
            return gregorianCutoverDate;
        }
    }
    // January 1 of the normalized year should exist.
    BaseCalendar juliancal = getJulianCalendarSystem();
    return juliancal.getFixedDate(date.getNormalizedYear(), BaseCalendar.JANUARY, 1, null);
}
 
Example #5
Source File: GregorianCalendar.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the given year is a leap year. Returns <code>true</code> if
 * the given year is a leap year. To specify BC year numbers,
 * <code>1 - year number</code> must be given. For example, year BC 4 is
 * specified as -3.
 *
 * @param year the given year.
 * @return <code>true</code> if the given year is a leap year; <code>false</code> otherwise.
 */
public boolean isLeapYear(int year) {
    if ((year & 3) != 0) {
        return false;
    }

    if (year > gregorianCutoverYear) {
        return (year%100 != 0) || (year%400 == 0); // Gregorian
    }
    if (year < gregorianCutoverYearJulian) {
        return true; // Julian
    }
    boolean gregorian;
    // If the given year is the Gregorian cutover year, we need to
    // determine which calendar system to be applied to February in the year.
    if (gregorianCutoverYear == gregorianCutoverYearJulian) {
        BaseCalendar.Date d = getCalendarDate(gregorianCutoverDate); // Gregorian
        gregorian = d.getMonth() < BaseCalendar.MARCH;
    } else {
        gregorian = year == gregorianCutoverYear;
    }
    return gregorian ? (year%100 != 0) || (year%400 == 0) : true;
}
 
Example #6
Source File: Date.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the month of this date to the specified value. This
 * <tt>Date</tt> object is modified so that it represents a point
 * in time within the specified month, with the year, date, hour,
 * minute, and second the same as before, as interpreted in the
 * local time zone. If the date was October 31, for example, and
 * the month is set to June, then the new date will be treated as
 * if it were on July 1, because June has only 30 days.
 *
 * @param   month   the month value between 0-11.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(Calendar.MONTH, int month)</code>.
 */
@Deprecated
public void setMonth(int month) {
    int y = 0;
    if (month >= 12) {
        y = month / 12;
        month %= 12;
    } else if (month < 0) {
        y = CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    BaseCalendar.Date d = getCalendarDate();
    if (y != 0) {
        d.setNormalizedYear(d.getNormalizedYear() + y);
    }
    d.setMonth(month + 1); // adjust 0-based to 1-based month numbering
}
 
Example #7
Source File: GregorianCalendar.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the fixed date of the first day of the year (usually
 * January 1) before the specified date.
 *
 * @param date the date for which the first day of the year is
 * calculated. The date has to be in the cut-over year (Gregorian
 * or Julian).
 * @param fixedDate the fixed date representation of the date
 */
private long getFixedDateJan1(BaseCalendar.Date date, long fixedDate) {
    assert date.getNormalizedYear() == gregorianCutoverYear ||
        date.getNormalizedYear() == gregorianCutoverYearJulian;
    if (gregorianCutoverYear != gregorianCutoverYearJulian) {
        if (fixedDate >= gregorianCutoverDate) {
            // Dates before the cutover date don't exist
            // in the same (Gregorian) year. So, no
            // January 1 exists in the year. Use the
            // cutover date as the first day of the year.
            return gregorianCutoverDate;
        }
    }
    // January 1 of the normalized year should exist.
    BaseCalendar juliancal = getJulianCalendarSystem();
    return juliancal.getFixedDate(date.getNormalizedYear(), BaseCalendar.JANUARY, 1, null);
}
 
Example #8
Source File: GregorianCalendar.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Override
public Object clone()
{
    GregorianCalendar other = (GregorianCalendar) super.clone();

    other.gdate = (BaseCalendar.Date) gdate.clone();
    if (cdate != null) {
        if (cdate != gdate) {
            other.cdate = (BaseCalendar.Date) cdate.clone();
        } else {
            other.cdate = other.gdate;
        }
    }
    other.originalFields = null;
    other.zoneOffsets = null;
    return other;
}
 
Example #9
Source File: GregorianCalendar.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determines if the given year is a leap year. Returns <code>true</code> if
 * the given year is a leap year. To specify BC year numbers,
 * <code>1 - year number</code> must be given. For example, year BC 4 is
 * specified as -3.
 *
 * @param year the given year.
 * @return <code>true</code> if the given year is a leap year; <code>false</code> otherwise.
 */
public boolean isLeapYear(int year) {
    if ((year & 3) != 0) {
        return false;
    }

    if (year > gregorianCutoverYear) {
        return (year%100 != 0) || (year%400 == 0); // Gregorian
    }
    if (year < gregorianCutoverYearJulian) {
        return true; // Julian
    }
    boolean gregorian;
    // If the given year is the Gregorian cutover year, we need to
    // determine which calendar system to be applied to February in the year.
    if (gregorianCutoverYear == gregorianCutoverYearJulian) {
        BaseCalendar.Date d = getCalendarDate(gregorianCutoverDate); // Gregorian
        gregorian = d.getMonth() < BaseCalendar.MARCH;
    } else {
        gregorian = year == gregorianCutoverYear;
    }
    return gregorian ? (year%100 != 0) || (year%400 == 0) : true;
}
 
Example #10
Source File: Date.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the month of this date to the specified value. This
 * <tt>Date</tt> object is modified so that it represents a point
 * in time within the specified month, with the year, date, hour,
 * minute, and second the same as before, as interpreted in the
 * local time zone. If the date was October 31, for example, and
 * the month is set to June, then the new date will be treated as
 * if it were on July 1, because June has only 30 days.
 *
 * @param   month   the month value between 0-11.
 * @see     java.util.Calendar
 * @deprecated As of JDK version 1.1,
 * replaced by <code>Calendar.set(Calendar.MONTH, int month)</code>.
 */
@Deprecated
public void setMonth(int month) {
    int y = 0;
    if (month >= 12) {
        y = month / 12;
        month %= 12;
    } else if (month < 0) {
        y = CalendarUtils.floorDivide(month, 12);
        month = CalendarUtils.mod(month, 12);
    }
    BaseCalendar.Date d = getCalendarDate();
    if (y != 0) {
        d.setNormalizedYear(d.getNormalizedYear() + y);
    }
    d.setMonth(month + 1); // adjust 0-based to 1-based month numbering
}
 
Example #11
Source File: GregorianCalendar.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a CalendarDate produced from the specified fixed date.
 *
 * @param fd the fixed date
 */
private BaseCalendar.Date getCalendarDate(long fd) {
    BaseCalendar cal = (fd >= gregorianCutoverDate) ? gcal : getJulianCalendarSystem();
    BaseCalendar.Date d = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
    cal.getCalendarDateFromFixedDate(d, fd);
    return d;
}
 
Example #12
Source File: GregorianCalendar.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a CalendarDate produced from the specified fixed date.
 *
 * @param fd the fixed date
 */
private BaseCalendar.Date getCalendarDate(long fd) {
    BaseCalendar cal = (fd >= gregorianCutoverDate) ? gcal : getJulianCalendarSystem();
    BaseCalendar.Date d = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
    cal.getCalendarDateFromFixedDate(d, fd);
    return d;
}
 
Example #13
Source File: GregorianCalendar.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates internal state.
 */
private void readObject(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    if (gdate == null) {
        gdate = (BaseCalendar.Date) gcal.newCalendarDate(getZone());
        cachedFixedDate = Long.MIN_VALUE;
    }
    setGregorianChange(gregorianCutover);
}
 
Example #14
Source File: GregorianCalendar.java    From openjdk-jdk8u 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 #15
Source File: SimpleTimeZone.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private long getStart(BaseCalendar cal, BaseCalendar.Date cdate, int year) {
    int time = startTime;
    if (startTimeMode != UTC_TIME) {
        time -= rawOffset;
    }
    return getTransition(cal, cdate, startMode, year, startMonth, startDay,
                         startDayOfWeek, time);
}
 
Example #16
Source File: SimpleTimeZone.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private long getTransition(BaseCalendar cal, BaseCalendar.Date cdate,
                           int mode, int year, int month, int dayOfMonth,
                           int dayOfWeek, int timeOfDay) {
    cdate.setNormalizedYear(year);
    cdate.setMonth(month + 1);
    switch (mode) {
    case DOM_MODE:
        cdate.setDayOfMonth(dayOfMonth);
        break;

    case DOW_IN_MONTH_MODE:
        cdate.setDayOfMonth(1);
        if (dayOfMonth < 0) {
            cdate.setDayOfMonth(cal.getMonthLength(cdate));
        }
        cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(dayOfMonth, dayOfWeek, cdate);
        break;

    case DOW_GE_DOM_MODE:
        cdate.setDayOfMonth(dayOfMonth);
        cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(1, dayOfWeek, cdate);
        break;

    case DOW_LE_DOM_MODE:
        cdate.setDayOfMonth(dayOfMonth);
        cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(-1, dayOfWeek, cdate);
        break;
    }
    return cal.getTime(cdate) + timeOfDay;
}
 
Example #17
Source File: SimpleTimeZone.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private long getTransition(BaseCalendar cal, BaseCalendar.Date cdate,
                           int mode, int year, int month, int dayOfMonth,
                           int dayOfWeek, int timeOfDay) {
    cdate.setNormalizedYear(year);
    cdate.setMonth(month + 1);
    switch (mode) {
    case DOM_MODE:
        cdate.setDayOfMonth(dayOfMonth);
        break;

    case DOW_IN_MONTH_MODE:
        cdate.setDayOfMonth(1);
        if (dayOfMonth < 0) {
            cdate.setDayOfMonth(cal.getMonthLength(cdate));
        }
        cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(dayOfMonth, dayOfWeek, cdate);
        break;

    case DOW_GE_DOM_MODE:
        cdate.setDayOfMonth(dayOfMonth);
        cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(1, dayOfWeek, cdate);
        break;

    case DOW_LE_DOM_MODE:
        cdate.setDayOfMonth(dayOfMonth);
        cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(-1, dayOfWeek, cdate);
        break;
    }
    return cal.getTime(cdate) + timeOfDay;
}
 
Example #18
Source File: GregorianCalendar.java    From hottub 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 #19
Source File: GregorianCalendar.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates internal state.
 */
private void readObject(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    if (gdate == null) {
        gdate = (BaseCalendar.Date) gcal.newCalendarDate(getZone());
        cachedFixedDate = Long.MIN_VALUE;
    }
    setGregorianChange(gregorianCutover);
}
 
Example #20
Source File: SimpleTimeZone.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private long getEnd(BaseCalendar cal, BaseCalendar.Date cdate, int year) {
    int time = endTime;
    if (endTimeMode != UTC_TIME) {
        time -= rawOffset;
    }
    if (endTimeMode == WALL_TIME) {
        time -= dstSavings;
    }
    return getTransition(cal, cdate, endMode, year, endMonth, endDay,
                                    endDayOfWeek, time);
}
 
Example #21
Source File: Date.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the millisecond value of this <code>Date</code> object
 * without affecting its internal state.
 */
static final long getMillisOf(Date date) {
    if (date.cdate == null || date.cdate.isNormalized()) {
        return date.fastTime;
    }
    BaseCalendar.Date d = (BaseCalendar.Date) date.cdate.clone();
    return gcal.getTime(d);
}
 
Example #22
Source File: SimpleTimeZone.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see TimeZone#getOffsets
 */
int getOffsets(long date, int[] offsets) {
    int offset = rawOffset;

  computeOffset:
    if (useDaylight) {
        synchronized (this) {
            if (cacheStart != 0) {
                if (date >= cacheStart && date < cacheEnd) {
                    offset += dstSavings;
                    break computeOffset;
                }
            }
        }
        BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ?
            gcal : (BaseCalendar) CalendarSystem.forName("julian");
        BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
        // Get the year in local time
        cal.getCalendarDate(date + rawOffset, cdate);
        int year = cdate.getNormalizedYear();
        if (year >= startYear) {
            // Clear time elements for the transition calculations
            cdate.setTimeOfDay(0, 0, 0, 0);
            offset = getOffset(cal, cdate, year, date);
        }
    }

    if (offsets != null) {
        offsets[0] = rawOffset;
        offsets[1] = offset - rawOffset;
    }
    return offset;
}
 
Example #23
Source File: SimpleTimeZone.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * @see TimeZone#getOffsets
 */
int getOffsets(long date, int[] offsets) {
    int offset = rawOffset;

  computeOffset:
    if (useDaylight) {
        synchronized (this) {
            if (cacheStart != 0) {
                if (date >= cacheStart && date < cacheEnd) {
                    offset += dstSavings;
                    break computeOffset;
                }
            }
        }
        BaseCalendar cal = date >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER ?
            gcal : (BaseCalendar) CalendarSystem.forName("julian");
        BaseCalendar.Date cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
        // Get the year in local time
        cal.getCalendarDate(date + rawOffset, cdate);
        int year = cdate.getNormalizedYear();
        if (year >= startYear) {
            // Clear time elements for the transition calculations
            cdate.setTimeOfDay(0, 0, 0, 0);
            offset = getOffset(cal, cdate, year, date);
        }
    }

    if (offsets != null) {
        offsets[0] = rawOffset;
        offsets[1] = offset - rawOffset;
    }
    return offset;
}
 
Example #24
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 #25
Source File: GregorianCalendar.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a CalendarDate produced from the specified fixed date.
 *
 * @param fd the fixed date
 */
private final BaseCalendar.Date getCalendarDate(long fd) {
    BaseCalendar cal = (fd >= gregorianCutoverDate) ? gcal : getJulianCalendarSystem();
    BaseCalendar.Date d = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
    cal.getCalendarDateFromFixedDate(d, fd);
    return d;
}
 
Example #26
Source File: GregorianCalendar.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a CalendarDate produced from the specified fixed date.
 *
 * @param fd the fixed date
 */
private BaseCalendar.Date getCalendarDate(long fd) {
    BaseCalendar cal = (fd >= gregorianCutoverDate) ? gcal : getJulianCalendarSystem();
    BaseCalendar.Date d = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
    cal.getCalendarDateFromFixedDate(d, fd);
    return d;
}
 
Example #27
Source File: GregorianCalendar.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns a CalendarDate produced from the specified fixed date.
 *
 * @param fd the fixed date
 */
private BaseCalendar.Date getCalendarDate(long fd) {
    BaseCalendar cal = (fd >= gregorianCutoverDate) ? gcal : getJulianCalendarSystem();
    BaseCalendar.Date d = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.NO_TIMEZONE);
    cal.getCalendarDateFromFixedDate(d, fd);
    return d;
}
 
Example #28
Source File: SimpleTimeZone.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private long getTransition(BaseCalendar cal, BaseCalendar.Date cdate,
                           int mode, int year, int month, int dayOfMonth,
                           int dayOfWeek, int timeOfDay) {
    cdate.setNormalizedYear(year);
    cdate.setMonth(month + 1);
    switch (mode) {
    case DOM_MODE:
        cdate.setDayOfMonth(dayOfMonth);
        break;

    case DOW_IN_MONTH_MODE:
        cdate.setDayOfMonth(1);
        if (dayOfMonth < 0) {
            cdate.setDayOfMonth(cal.getMonthLength(cdate));
        }
        cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(dayOfMonth, dayOfWeek, cdate);
        break;

    case DOW_GE_DOM_MODE:
        cdate.setDayOfMonth(dayOfMonth);
        cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(1, dayOfWeek, cdate);
        break;

    case DOW_LE_DOM_MODE:
        cdate.setDayOfMonth(dayOfMonth);
        cdate = (BaseCalendar.Date) cal.getNthDayOfWeek(-1, dayOfWeek, cdate);
        break;
    }
    return cal.getTime(cdate) + timeOfDay;
}
 
Example #29
Source File: SimpleTimeZone.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private long getEnd(BaseCalendar cal, BaseCalendar.Date cdate, int year) {
    int time = endTime;
    if (endTimeMode != UTC_TIME) {
        time -= rawOffset;
    }
    if (endTimeMode == WALL_TIME) {
        time -= dstSavings;
    }
    return getTransition(cal, cdate, endMode, year, endMonth, endDay,
                                    endDayOfWeek, time);
}
 
Example #30
Source File: GregorianCalendar.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the calendar system for dates before the cutover date
 * in the cutover year. If the cutover date is January 1, the
 * method returns Gregorian. Otherwise, Julian.
 */
private BaseCalendar getCutoverCalendarSystem() {
    if (gregorianCutoverYearJulian < gregorianCutoverYear) {
        return gcal;
    }
    return getJulianCalendarSystem();
}