Java Code Examples for sun.util.calendar.CalendarDate#setDate()

The following examples show how to use sun.util.calendar.CalendarDate#setDate() . 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: Time.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts the given Gregorian calendar field values to local time.
 * Local time is represented by the amount of milliseconds from
 * January 1, 1970 0:00 GMT.
 * @param year the year value
 * @param month the Month value
 * @param day the day represented by {@link RuleDay}
 * @param time the time of the day represented by {@link Time}
 * @return local time
 */
static long getLocalTime(int year, Month month, RuleDay day, int time) {
    CalendarDate cdate = gcal.newCalendarDate(null);
    int monthValue = month.value();

    if (day.isLast()) {     // e.g., "lastSun"
        cdate.setDate(year, monthValue, 1);
        cdate.setDayOfMonth(gcal.getMonthLength(cdate));
        cdate = gcal.getNthDayOfWeek(-1, day.getDayOfWeekNum(), cdate);
    } else if (day.isLater()) { // e.g., "Sun>=1"
        cdate.setDate(year, monthValue, day.getDay());
        cdate = gcal.getNthDayOfWeek(1, day.getDayOfWeekNum(), cdate);
    } else if (day.isExact()) {
        cdate.setDate(year, monthValue, day.getDay());
    } else if (day.isEarlier()) {   // e.g., "Sun<=15"
        cdate.setDate(year, monthValue, day.getDay());
        cdate = gcal.getNthDayOfWeek(-1, day.getDayOfWeekNum(), cdate);
    } else {
        Main.panic("invalid day type: " + day);
    }
    return gcal.getTime(cdate) + time;
}
 
Example 2
Source File: Time.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts the given Gregorian calendar field values to local time.
 * Local time is represented by the amount of milliseconds from
 * January 1, 1970 0:00 GMT.
 * @param year the year value
 * @param month the Month value
 * @param day the day represented by {@link RuleDay}
 * @param time the time of the day represented by {@link Time}
 * @return local time
 */
static long getLocalTime(int year, Month month, RuleDay day, int time) {
    CalendarDate cdate = gcal.newCalendarDate(null);
    int monthValue = month.value();

    if (day.isLast()) {     // e.g., "lastSun"
        cdate.setDate(year, monthValue, 1);
        cdate.setDayOfMonth(gcal.getMonthLength(cdate));
        cdate = gcal.getNthDayOfWeek(-1, day.getDayOfWeekNum(), cdate);
    } else if (day.isLater()) { // e.g., "Sun>=1"
        cdate.setDate(year, monthValue, day.getDay());
        cdate = gcal.getNthDayOfWeek(1, day.getDayOfWeekNum(), cdate);
    } else if (day.isExact()) {
        cdate.setDate(year, monthValue, day.getDay());
    } else if (day.isEarlier()) {   // e.g., "Sun<=15"
        cdate.setDate(year, monthValue, day.getDay());
        cdate = gcal.getNthDayOfWeek(-1, day.getDayOfWeekNum(), cdate);
    } else {
        Main.panic("invalid day type: " + day);
    }
    return gcal.getTime(cdate) + time;
}
 
Example 3
Source File: Time.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts the given Gregorian calendar field values to local time.
 * Local time is represented by the amount of milliseconds from
 * January 1, 1970 0:00 GMT.
 * @param year the year value
 * @param month the Month value
 * @param day the day represented by {@link RuleDay}
 * @param time the time of the day represented by {@link Time}
 * @return local time
 */
static long getLocalTime(int year, Month month, RuleDay day, int time) {
    CalendarDate cdate = gcal.newCalendarDate(null);
    int monthValue = month.value();

    if (day.isLast()) {     // e.g., "lastSun"
        cdate.setDate(year, monthValue, 1);
        cdate.setDayOfMonth(gcal.getMonthLength(cdate));
        cdate = gcal.getNthDayOfWeek(-1, day.getDayOfWeekNum(), cdate);
    } else if (day.isLater()) { // e.g., "Sun>=1"
        cdate.setDate(year, monthValue, day.getDay());
        cdate = gcal.getNthDayOfWeek(1, day.getDayOfWeekNum(), cdate);
    } else if (day.isExact()) {
        cdate.setDate(year, monthValue, day.getDay());
    } else if (day.isEarlier()) {   // e.g., "Sun<=15"
        cdate.setDate(year, monthValue, day.getDay());
        cdate = gcal.getNthDayOfWeek(-1, day.getDayOfWeekNum(), cdate);
    } else {
        Main.panic("invalid day type: " + day);
    }
    return gcal.getTime(cdate) + time;
}
 
Example 4
Source File: Time.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts the given Gregorian calendar field values to local time.
 * Local time is represented by the amount of milliseconds from
 * January 1, 1970 0:00 GMT.
 * @param year the year value
 * @param month the Month value
 * @param day the day represented by {@link RuleDay}
 * @param time the time of the day represented by {@link Time}
 * @return local time
 */
static long getLocalTime(int year, Month month, RuleDay day, int time) {
    CalendarDate cdate = gcal.newCalendarDate(null);
    int monthValue = month.value();

    if (day.isLast()) {     // e.g., "lastSun"
        cdate.setDate(year, monthValue, 1);
        cdate.setDayOfMonth(gcal.getMonthLength(cdate));
        cdate = gcal.getNthDayOfWeek(-1, day.getDayOfWeekNum(), cdate);
    } else if (day.isLater()) { // e.g., "Sun>=1"
        cdate.setDate(year, monthValue, day.getDay());
        cdate = gcal.getNthDayOfWeek(1, day.getDayOfWeekNum(), cdate);
    } else if (day.isExact()) {
        cdate.setDate(year, monthValue, day.getDay());
    } else if (day.isEarlier()) {   // e.g., "Sun<=15"
        cdate.setDate(year, monthValue, day.getDay());
        cdate = gcal.getNthDayOfWeek(-1, day.getDayOfWeekNum(), cdate);
    } else {
        Main.panic("invalid day type: " + day);
    }
    return gcal.getTime(cdate) + time;
}
 
Example 5
Source File: Time.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts the given Gregorian calendar field values to local time.
 * Local time is represented by the amount of milliseconds from
 * January 1, 1970 0:00 GMT.
 * @param year the year value
 * @param month the Month value
 * @param day the day represented by {@link RuleDay}
 * @param time the time of the day represented by {@link Time}
 * @return local time
 */
static long getLocalTime(int year, Month month, RuleDay day, int time) {
    CalendarDate cdate = gcal.newCalendarDate(null);
    int monthValue = month.value();

    if (day.isLast()) {     // e.g., "lastSun"
        cdate.setDate(year, monthValue, 1);
        cdate.setDayOfMonth(gcal.getMonthLength(cdate));
        cdate = gcal.getNthDayOfWeek(-1, day.getDayOfWeekNum(), cdate);
    } else if (day.isLater()) { // e.g., "Sun>=1"
        cdate.setDate(year, monthValue, day.getDay());
        cdate = gcal.getNthDayOfWeek(1, day.getDayOfWeekNum(), cdate);
    } else if (day.isExact()) {
        cdate.setDate(year, monthValue, day.getDay());
    } else if (day.isEarlier()) {   // e.g., "Sun<=15"
        cdate.setDate(year, monthValue, day.getDay());
        cdate = gcal.getNthDayOfWeek(-1, day.getDayOfWeekNum(), cdate);
    } else {
        Main.panic("invalid day type: " + day);
    }
    return gcal.getTime(cdate) + time;
}
 
Example 6
Source File: ZoneInfoOld.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the difference in milliseconds between local time and
 * UTC, taking into account both the raw offset and the effect of
 * daylight savings, for the specified date and time.  This method
 * assumes that the start and end month are distinct.  This method
 * assumes a Gregorian calendar for calculations.
 * <p>
 * <em>Note: In general, clients should use
 * {@link Calendar#ZONE_OFFSET Calendar.get(ZONE_OFFSET)} +
 * {@link Calendar#DST_OFFSET Calendar.get(DST_OFFSET)}
 * instead of calling this method.</em>
 *
 * @param era       The era of the given date. The value must be either
 *                  GregorianCalendar.AD or GregorianCalendar.BC.
 * @param year      The year in the given date.
 * @param month     The month in the given date. Month is 0-based. e.g.,
 *                  0 for January.
 * @param day       The day-in-month of the given date.
 * @param dayOfWeek The day-of-week of the given date.
 * @param millis    The milliseconds in day in <em>standard</em> local time.
 * @return The milliseconds to add to UTC to get local time.
 */
public int getOffset(int era, int year, int month, int day,
                     int dayOfWeek, int milliseconds) {
    if (milliseconds < 0 || milliseconds >= DAY_IN_MILLIS) {
        throw new IllegalArgumentException();
    }

    if (era == java.util.GregorianCalendar.BC) { // BC
        year = 1 - year;
    } else if (era != java.util.GregorianCalendar.AD) {
        throw new IllegalArgumentException();
    }

    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month + 1, day);
    if (gcal.validate(date) == false) {
        throw new IllegalArgumentException();
    }

    // bug-for-bug compatible argument checking
    if (dayOfWeek < java.util.GregorianCalendar.SUNDAY
        || dayOfWeek > java.util.GregorianCalendar.SATURDAY) {
        throw new IllegalArgumentException();
    }

    if (transitions == null) {
        return getLastRawOffset();
    }

    long dateInMillis = gcal.getTime(date) + milliseconds;
    dateInMillis -= (long) rawOffset; // make it UTC
    return getOffsets(dateInMillis, null, UTC_TIME);
}
 
Example 7
Source File: ZoneInfoOld.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the difference in milliseconds between local time and
 * UTC, taking into account both the raw offset and the effect of
 * daylight savings, for the specified date and time.  This method
 * assumes that the start and end month are distinct.  This method
 * assumes a Gregorian calendar for calculations.
 * <p>
 * <em>Note: In general, clients should use
 * {@link Calendar#ZONE_OFFSET Calendar.get(ZONE_OFFSET)} +
 * {@link Calendar#DST_OFFSET Calendar.get(DST_OFFSET)}
 * instead of calling this method.</em>
 *
 * @param era       The era of the given date. The value must be either
 *                  GregorianCalendar.AD or GregorianCalendar.BC.
 * @param year      The year in the given date.
 * @param month     The month in the given date. Month is 0-based. e.g.,
 *                  0 for January.
 * @param day       The day-in-month of the given date.
 * @param dayOfWeek The day-of-week of the given date.
 * @param millis    The milliseconds in day in <em>standard</em> local time.
 * @return The milliseconds to add to UTC to get local time.
 */
public int getOffset(int era, int year, int month, int day,
                     int dayOfWeek, int milliseconds) {
    if (milliseconds < 0 || milliseconds >= DAY_IN_MILLIS) {
        throw new IllegalArgumentException();
    }

    if (era == java.util.GregorianCalendar.BC) { // BC
        year = 1 - year;
    } else if (era != java.util.GregorianCalendar.AD) {
        throw new IllegalArgumentException();
    }

    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month + 1, day);
    if (gcal.validate(date) == false) {
        throw new IllegalArgumentException();
    }

    // bug-for-bug compatible argument checking
    if (dayOfWeek < java.util.GregorianCalendar.SUNDAY
        || dayOfWeek > java.util.GregorianCalendar.SATURDAY) {
        throw new IllegalArgumentException();
    }

    if (transitions == null) {
        return getLastRawOffset();
    }

    long dateInMillis = gcal.getTime(date) + milliseconds;
    dateInMillis -= (long) rawOffset; // make it UTC
    return getOffsets(dateInMillis, null, UTC_TIME);
}
 
Example 8
Source File: ZoneInfoOld.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the difference in milliseconds between local time and
 * UTC, taking into account both the raw offset and the effect of
 * daylight savings, for the specified date and time.  This method
 * assumes that the start and end month are distinct.  This method
 * assumes a Gregorian calendar for calculations.
 * <p>
 * <em>Note: In general, clients should use
 * {@link Calendar#ZONE_OFFSET Calendar.get(ZONE_OFFSET)} +
 * {@link Calendar#DST_OFFSET Calendar.get(DST_OFFSET)}
 * instead of calling this method.</em>
 *
 * @param era       The era of the given date. The value must be either
 *                  GregorianCalendar.AD or GregorianCalendar.BC.
 * @param year      The year in the given date.
 * @param month     The month in the given date. Month is 0-based. e.g.,
 *                  0 for January.
 * @param day       The day-in-month of the given date.
 * @param dayOfWeek The day-of-week of the given date.
 * @param millis    The milliseconds in day in <em>standard</em> local time.
 * @return The milliseconds to add to UTC to get local time.
 */
public int getOffset(int era, int year, int month, int day,
                     int dayOfWeek, int milliseconds) {
    if (milliseconds < 0 || milliseconds >= DAY_IN_MILLIS) {
        throw new IllegalArgumentException();
    }

    if (era == java.util.GregorianCalendar.BC) { // BC
        year = 1 - year;
    } else if (era != java.util.GregorianCalendar.AD) {
        throw new IllegalArgumentException();
    }

    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month + 1, day);
    if (gcal.validate(date) == false) {
        throw new IllegalArgumentException();
    }

    // bug-for-bug compatible argument checking
    if (dayOfWeek < java.util.GregorianCalendar.SUNDAY
        || dayOfWeek > java.util.GregorianCalendar.SATURDAY) {
        throw new IllegalArgumentException();
    }

    if (transitions == null) {
        return getLastRawOffset();
    }

    long dateInMillis = gcal.getTime(date) + milliseconds;
    dateInMillis -= (long) rawOffset; // make it UTC
    return getOffsets(dateInMillis, null, UTC_TIME);
}
 
Example 9
Source File: ZoneInfoOld.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the difference in milliseconds between local time and
 * UTC, taking into account both the raw offset and the effect of
 * daylight savings, for the specified date and time.  This method
 * assumes that the start and end month are distinct.  This method
 * assumes a Gregorian calendar for calculations.
 * <p>
 * <em>Note: In general, clients should use
 * {@link Calendar#ZONE_OFFSET Calendar.get(ZONE_OFFSET)} +
 * {@link Calendar#DST_OFFSET Calendar.get(DST_OFFSET)}
 * instead of calling this method.</em>
 *
 * @param era       The era of the given date. The value must be either
 *                  GregorianCalendar.AD or GregorianCalendar.BC.
 * @param year      The year in the given date.
 * @param month     The month in the given date. Month is 0-based. e.g.,
 *                  0 for January.
 * @param day       The day-in-month of the given date.
 * @param dayOfWeek The day-of-week of the given date.
 * @param millis    The milliseconds in day in <em>standard</em> local time.
 * @return The milliseconds to add to UTC to get local time.
 */
public int getOffset(int era, int year, int month, int day,
                     int dayOfWeek, int milliseconds) {
    if (milliseconds < 0 || milliseconds >= DAY_IN_MILLIS) {
        throw new IllegalArgumentException();
    }

    if (era == java.util.GregorianCalendar.BC) { // BC
        year = 1 - year;
    } else if (era != java.util.GregorianCalendar.AD) {
        throw new IllegalArgumentException();
    }

    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month + 1, day);
    if (gcal.validate(date) == false) {
        throw new IllegalArgumentException();
    }

    // bug-for-bug compatible argument checking
    if (dayOfWeek < java.util.GregorianCalendar.SUNDAY
        || dayOfWeek > java.util.GregorianCalendar.SATURDAY) {
        throw new IllegalArgumentException();
    }

    if (transitions == null) {
        return getLastRawOffset();
    }

    long dateInMillis = gcal.getTime(date) + milliseconds;
    dateInMillis -= (long) rawOffset; // make it UTC
    return getOffsets(dateInMillis, null, UTC_TIME);
}
 
Example 10
Source File: ZoneInfoOld.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the difference in milliseconds between local time and
 * UTC, taking into account both the raw offset and the effect of
 * daylight savings, for the specified date and time.  This method
 * assumes that the start and end month are distinct.  This method
 * assumes a Gregorian calendar for calculations.
 * <p>
 * <em>Note: In general, clients should use
 * {@link Calendar#ZONE_OFFSET Calendar.get(ZONE_OFFSET)} +
 * {@link Calendar#DST_OFFSET Calendar.get(DST_OFFSET)}
 * instead of calling this method.</em>
 *
 * @param era       The era of the given date. The value must be either
 *                  GregorianCalendar.AD or GregorianCalendar.BC.
 * @param year      The year in the given date.
 * @param month     The month in the given date. Month is 0-based. e.g.,
 *                  0 for January.
 * @param day       The day-in-month of the given date.
 * @param dayOfWeek The day-of-week of the given date.
 * @param millis    The milliseconds in day in <em>standard</em> local time.
 * @return The milliseconds to add to UTC to get local time.
 */
public int getOffset(int era, int year, int month, int day,
                     int dayOfWeek, int milliseconds) {
    if (milliseconds < 0 || milliseconds >= DAY_IN_MILLIS) {
        throw new IllegalArgumentException();
    }

    if (era == java.util.GregorianCalendar.BC) { // BC
        year = 1 - year;
    } else if (era != java.util.GregorianCalendar.AD) {
        throw new IllegalArgumentException();
    }

    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month + 1, day);
    if (gcal.validate(date) == false) {
        throw new IllegalArgumentException();
    }

    // bug-for-bug compatible argument checking
    if (dayOfWeek < java.util.GregorianCalendar.SUNDAY
        || dayOfWeek > java.util.GregorianCalendar.SATURDAY) {
        throw new IllegalArgumentException();
    }

    if (transitions == null) {
        return getLastRawOffset();
    }

    long dateInMillis = gcal.getTime(date) + milliseconds;
    dateInMillis -= (long) rawOffset; // make it UTC
    return getOffsets(dateInMillis, null, UTC_TIME);
}
 
Example 11
Source File: ZoneInfoOld.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the difference in milliseconds between local time and
 * UTC, taking into account both the raw offset and the effect of
 * daylight savings, for the specified date and time.  This method
 * assumes that the start and end month are distinct.  This method
 * assumes a Gregorian calendar for calculations.
 * <p>
 * <em>Note: In general, clients should use
 * {@link Calendar#ZONE_OFFSET Calendar.get(ZONE_OFFSET)} +
 * {@link Calendar#DST_OFFSET Calendar.get(DST_OFFSET)}
 * instead of calling this method.</em>
 *
 * @param era       The era of the given date. The value must be either
 *                  GregorianCalendar.AD or GregorianCalendar.BC.
 * @param year      The year in the given date.
 * @param month     The month in the given date. Month is 0-based. e.g.,
 *                  0 for January.
 * @param day       The day-in-month of the given date.
 * @param dayOfWeek The day-of-week of the given date.
 * @param millis    The milliseconds in day in <em>standard</em> local time.
 * @return The milliseconds to add to UTC to get local time.
 */
public int getOffset(int era, int year, int month, int day,
                     int dayOfWeek, int milliseconds) {
    if (milliseconds < 0 || milliseconds >= DAY_IN_MILLIS) {
        throw new IllegalArgumentException();
    }

    if (era == java.util.GregorianCalendar.BC) { // BC
        year = 1 - year;
    } else if (era != java.util.GregorianCalendar.AD) {
        throw new IllegalArgumentException();
    }

    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month + 1, day);
    if (gcal.validate(date) == false) {
        throw new IllegalArgumentException();
    }

    // bug-for-bug compatible argument checking
    if (dayOfWeek < java.util.GregorianCalendar.SUNDAY
        || dayOfWeek > java.util.GregorianCalendar.SATURDAY) {
        throw new IllegalArgumentException();
    }

    if (transitions == null) {
        return getLastRawOffset();
    }

    long dateInMillis = gcal.getTime(date) + milliseconds;
    dateInMillis -= (long) rawOffset; // make it UTC
    return getOffsets(dateInMillis, null, UTC_TIME);
}
 
Example 12
Source File: ZoneInfoOld.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the difference in milliseconds between local time and
 * UTC, taking into account both the raw offset and the effect of
 * daylight savings, for the specified date and time.  This method
 * assumes that the start and end month are distinct.  This method
 * assumes a Gregorian calendar for calculations.
 * <p>
 * <em>Note: In general, clients should use
 * {@link Calendar#ZONE_OFFSET Calendar.get(ZONE_OFFSET)} +
 * {@link Calendar#DST_OFFSET Calendar.get(DST_OFFSET)}
 * instead of calling this method.</em>
 *
 * @param era       The era of the given date. The value must be either
 *                  GregorianCalendar.AD or GregorianCalendar.BC.
 * @param year      The year in the given date.
 * @param month     The month in the given date. Month is 0-based. e.g.,
 *                  0 for January.
 * @param day       The day-in-month of the given date.
 * @param dayOfWeek The day-of-week of the given date.
 * @param millis    The milliseconds in day in <em>standard</em> local time.
 * @return The milliseconds to add to UTC to get local time.
 */
public int getOffset(int era, int year, int month, int day,
                     int dayOfWeek, int milliseconds) {
    if (milliseconds < 0 || milliseconds >= DAY_IN_MILLIS) {
        throw new IllegalArgumentException();
    }

    if (era == java.util.GregorianCalendar.BC) { // BC
        year = 1 - year;
    } else if (era != java.util.GregorianCalendar.AD) {
        throw new IllegalArgumentException();
    }

    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month + 1, day);
    if (gcal.validate(date) == false) {
        throw new IllegalArgumentException();
    }

    // bug-for-bug compatible argument checking
    if (dayOfWeek < java.util.GregorianCalendar.SUNDAY
        || dayOfWeek > java.util.GregorianCalendar.SATURDAY) {
        throw new IllegalArgumentException();
    }

    if (transitions == null) {
        return getLastRawOffset();
    }

    long dateInMillis = gcal.getTime(date) + milliseconds;
    dateInMillis -= (long) rawOffset; // make it UTC
    return getOffsets(dateInMillis, null, UTC_TIME);
}
 
Example 13
Source File: ZoneInfoOld.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the difference in milliseconds between local time and
 * UTC, taking into account both the raw offset and the effect of
 * daylight savings, for the specified date and time.  This method
 * assumes that the start and end month are distinct.  This method
 * assumes a Gregorian calendar for calculations.
 * <p>
 * <em>Note: In general, clients should use
 * {@link Calendar#ZONE_OFFSET Calendar.get(ZONE_OFFSET)} +
 * {@link Calendar#DST_OFFSET Calendar.get(DST_OFFSET)}
 * instead of calling this method.</em>
 *
 * @param era       The era of the given date. The value must be either
 *                  GregorianCalendar.AD or GregorianCalendar.BC.
 * @param year      The year in the given date.
 * @param month     The month in the given date. Month is 0-based. e.g.,
 *                  0 for January.
 * @param day       The day-in-month of the given date.
 * @param dayOfWeek The day-of-week of the given date.
 * @param millis    The milliseconds in day in <em>standard</em> local time.
 * @return The milliseconds to add to UTC to get local time.
 */
public int getOffset(int era, int year, int month, int day,
                     int dayOfWeek, int milliseconds) {
    if (milliseconds < 0 || milliseconds >= DAY_IN_MILLIS) {
        throw new IllegalArgumentException();
    }

    if (era == java.util.GregorianCalendar.BC) { // BC
        year = 1 - year;
    } else if (era != java.util.GregorianCalendar.AD) {
        throw new IllegalArgumentException();
    }

    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month + 1, day);
    if (gcal.validate(date) == false) {
        throw new IllegalArgumentException();
    }

    // bug-for-bug compatible argument checking
    if (dayOfWeek < java.util.GregorianCalendar.SUNDAY
        || dayOfWeek > java.util.GregorianCalendar.SATURDAY) {
        throw new IllegalArgumentException();
    }

    if (transitions == null) {
        return getLastRawOffset();
    }

    long dateInMillis = gcal.getTime(date) + milliseconds;
    dateInMillis -= (long) rawOffset; // make it UTC
    return getOffsets(dateInMillis, null, UTC_TIME);
}
 
Example 14
Source File: ZoneInfoOld.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the difference in milliseconds between local time and
 * UTC, taking into account both the raw offset and the effect of
 * daylight savings, for the specified date and time.  This method
 * assumes that the start and end month are distinct.  This method
 * assumes a Gregorian calendar for calculations.
 * <p>
 * <em>Note: In general, clients should use
 * {@link Calendar#ZONE_OFFSET Calendar.get(ZONE_OFFSET)} +
 * {@link Calendar#DST_OFFSET Calendar.get(DST_OFFSET)}
 * instead of calling this method.</em>
 *
 * @param era       The era of the given date. The value must be either
 *                  GregorianCalendar.AD or GregorianCalendar.BC.
 * @param year      The year in the given date.
 * @param month     The month in the given date. Month is 0-based. e.g.,
 *                  0 for January.
 * @param day       The day-in-month of the given date.
 * @param dayOfWeek The day-of-week of the given date.
 * @param millis    The milliseconds in day in <em>standard</em> local time.
 * @return The milliseconds to add to UTC to get local time.
 */
public int getOffset(int era, int year, int month, int day,
                     int dayOfWeek, int milliseconds) {
    if (milliseconds < 0 || milliseconds >= DAY_IN_MILLIS) {
        throw new IllegalArgumentException();
    }

    if (era == java.util.GregorianCalendar.BC) { // BC
        year = 1 - year;
    } else if (era != java.util.GregorianCalendar.AD) {
        throw new IllegalArgumentException();
    }

    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month + 1, day);
    if (gcal.validate(date) == false) {
        throw new IllegalArgumentException();
    }

    // bug-for-bug compatible argument checking
    if (dayOfWeek < java.util.GregorianCalendar.SUNDAY
        || dayOfWeek > java.util.GregorianCalendar.SATURDAY) {
        throw new IllegalArgumentException();
    }

    if (transitions == null) {
        return getLastRawOffset();
    }

    long dateInMillis = gcal.getTime(date) + milliseconds;
    dateInMillis -= (long) rawOffset; // make it UTC
    return getOffsets(dateInMillis, null, UTC_TIME);
}
 
Example 15
Source File: Time.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Converts the given Gregorian calendar field values to local time.
 * Local time is represented by the amount of milliseconds from
 * January 1, 1970 0:00 GMT.
 * @param year the year value
 * @param month the Month value
 * @param day the day value
 * @param time the time of the day in milliseconds
 * @return local time
 */
static long getLocalTime(int year, Month month, int day, long time) {
    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month.value(), day);
    long millis = gcal.getTime(date);
    return millis + time;
}
 
Example 16
Source File: Time.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Converts the given Gregorian calendar field values to local time.
 * Local time is represented by the amount of milliseconds from
 * January 1, 1970 0:00 GMT.
 * @param year the year value
 * @param month the Month value
 * @param day the day value
 * @param time the time of the day in milliseconds
 * @return local time
 */
static long getLocalTime(int year, Month month, int day, long time) {
    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month.value(), day);
    long millis = gcal.getTime(date);
    return millis + time;
}
 
Example 17
Source File: Time.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Converts the given Gregorian calendar field values to local time.
 * Local time is represented by the amount of milliseconds from
 * January 1, 1970 0:00 GMT.
 * @param year the year value
 * @param month the Month value
 * @param day the day value
 * @param time the time of the day in milliseconds
 * @return local time
 */
static long getLocalTime(int year, Month month, int day, long time) {
    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month.value(), day);
    long millis = gcal.getTime(date);
    return millis + time;
}
 
Example 18
Source File: Time.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Converts the given Gregorian calendar field values to local time.
 * Local time is represented by the amount of milliseconds from
 * January 1, 1970 0:00 GMT.
 * @param year the year value
 * @param month the Month value
 * @param day the day value
 * @param time the time of the day in milliseconds
 * @return local time
 */
static long getLocalTime(int year, Month month, int day, long time) {
    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month.value(), day);
    long millis = gcal.getTime(date);
    return millis + time;
}
 
Example 19
Source File: Time.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Converts the given Gregorian calendar field values to local time.
 * Local time is represented by the amount of milliseconds from
 * January 1, 1970 0:00 GMT.
 * @param year the year value
 * @param month the Month value
 * @param day the day value
 * @param time the time of the day in milliseconds
 * @return local time
 */
static long getLocalTime(int year, Month month, int day, long time) {
    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month.value(), day);
    long millis = gcal.getTime(date);
    return millis + time;
}
 
Example 20
Source File: Time.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Converts the given Gregorian calendar field values to local time.
 * Local time is represented by the amount of milliseconds from
 * January 1, 1970 0:00 GMT.
 * @param year the year value
 * @param month the Month value
 * @param day the day value
 * @param time the time of the day in milliseconds
 * @return local time
 */
static long getLocalTime(int year, Month month, int day, long time) {
    CalendarDate date = gcal.newCalendarDate(null);
    date.setDate(year, month.value(), day);
    long millis = gcal.getTime(date);
    return millis + time;
}