sun.util.calendar.CalendarDate Java Examples

The following examples show how to use sun.util.calendar.CalendarDate. 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: JapaneseImperialCalendar.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the index to the new era if the given date is in a
 * transition month.  For example, if the give date is Heisei 1
 * (1989) January 20, then the era index for Heisei is
 * returned. Likewise, if the given date is Showa 64 (1989)
 * January 3, then the era index for Heisei is returned. If the
 * given date is not in any transition month, then -1 is returned.
 */
private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) {
    int eraIndex = getEraIndex(date);
    CalendarDate transitionDate = eras[eraIndex].getSinceDate();
    if (transitionDate.getYear() == date.getNormalizedYear() &&
        transitionDate.getMonth() == date.getMonth()) {
        return eraIndex;
    }
    if (eraIndex < eras.length - 1) {
        transitionDate = eras[++eraIndex].getSinceDate();
        if (transitionDate.getYear() == date.getNormalizedYear() &&
            transitionDate.getMonth() == date.getMonth()) {
            return eraIndex;
        }
    }
    return -1;
}
 
Example #2
Source File: Time.java    From dragonwell8_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 #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: JapaneseImperialCalendar.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the index to the new era if the given date is in a
 * transition month.  For example, if the give date is Heisei 1
 * (1989) January 20, then the era index for Heisei is
 * returned. Likewise, if the given date is Showa 64 (1989)
 * January 3, then the era index for Heisei is returned. If the
 * given date is not in any transition month, then -1 is returned.
 */
private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) {
    int eraIndex = getEraIndex(date);
    CalendarDate transitionDate = eras[eraIndex].getSinceDate();
    if (transitionDate.getYear() == date.getNormalizedYear() &&
        transitionDate.getMonth() == date.getMonth()) {
        return eraIndex;
    }
    if (eraIndex < eras.length - 1) {
        transitionDate = eras[++eraIndex].getSinceDate();
        if (transitionDate.getYear() == date.getNormalizedYear() &&
            transitionDate.getMonth() == date.getMonth()) {
            return eraIndex;
        }
    }
    return -1;
}
 
Example #5
Source File: JapaneseImperialCalendar.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the index to the new era if the given date is in a
 * transition month.  For example, if the give date is Heisei 1
 * (1989) January 20, then the era index for Heisei is
 * returned. Likewise, if the given date is Showa 64 (1989)
 * January 3, then the era index for Heisei is returned. If the
 * given date is not in any transition month, then -1 is returned.
 */
private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) {
    int eraIndex = getEraIndex(date);
    CalendarDate transitionDate = eras[eraIndex].getSinceDate();
    if (transitionDate.getYear() == date.getNormalizedYear() &&
        transitionDate.getMonth() == date.getMonth()) {
        return eraIndex;
    }
    if (eraIndex < eras.length - 1) {
        transitionDate = eras[++eraIndex].getSinceDate();
        if (transitionDate.getYear() == date.getNormalizedYear() &&
            transitionDate.getMonth() == date.getMonth()) {
            return eraIndex;
        }
    }
    return -1;
}
 
Example #6
Source File: JapaneseImperialCalendar.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the index to the new era if the given date is in a
 * transition month.  For example, if the give date is Heisei 1
 * (1989) January 20, then the era index for Heisei is
 * returned. Likewise, if the given date is Showa 64 (1989)
 * January 3, then the era index for Heisei is returned. If the
 * given date is not in any transition month, then -1 is returned.
 */
private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) {
    int eraIndex = getEraIndex(date);
    CalendarDate transitionDate = eras[eraIndex].getSinceDate();
    if (transitionDate.getYear() == date.getNormalizedYear() &&
        transitionDate.getMonth() == date.getMonth()) {
        return eraIndex;
    }
    if (eraIndex < eras.length - 1) {
        transitionDate = eras[++eraIndex].getSinceDate();
        if (transitionDate.getYear() == date.getNormalizedYear() &&
            transitionDate.getMonth() == date.getMonth()) {
            return eraIndex;
        }
    }
    return -1;
}
 
Example #7
Source File: Time.java    From openjdk-jdk9 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 #8
Source File: Time.java    From openjdk-8-source 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 #9
Source File: Time.java    From jdk8u-dev-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 #10
Source File: JapaneseImperialCalendar.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the index to the new era if the given date is in a
 * transition month.  For example, if the give date is Heisei 1
 * (1989) January 20, then the era index for Heisei is
 * returned. Likewise, if the given date is Showa 64 (1989)
 * January 3, then the era index for Heisei is returned. If the
 * given date is not in any transition month, then -1 is returned.
 */
private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) {
    int eraIndex = getEraIndex(date);
    CalendarDate transitionDate = eras[eraIndex].getSinceDate();
    if (transitionDate.getYear() == date.getNormalizedYear() &&
        transitionDate.getMonth() == date.getMonth()) {
        return eraIndex;
    }
    if (eraIndex < eras.length - 1) {
        transitionDate = eras[++eraIndex].getSinceDate();
        if (transitionDate.getYear() == date.getNormalizedYear() &&
            transitionDate.getMonth() == date.getMonth()) {
            return eraIndex;
        }
    }
    return -1;
}
 
Example #11
Source File: JapaneseImperialCalendar.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the index to the new era if the given date is in a
 * transition month.  For example, if the give date is Heisei 1
 * (1989) January 20, then the era index for Heisei is
 * returned. Likewise, if the given date is Showa 64 (1989)
 * January 3, then the era index for Heisei is returned. If the
 * given date is not in any transition month, then -1 is returned.
 */
private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) {
    int eraIndex = getEraIndex(date);
    CalendarDate transitionDate = eras[eraIndex].getSinceDate();
    if (transitionDate.getYear() == date.getNormalizedYear() &&
        transitionDate.getMonth() == date.getMonth()) {
        return eraIndex;
    }
    if (eraIndex < eras.length - 1) {
        transitionDate = eras[++eraIndex].getSinceDate();
        if (transitionDate.getYear() == date.getNormalizedYear() &&
            transitionDate.getMonth() == date.getMonth()) {
            return eraIndex;
        }
    }
    return -1;
}
 
Example #12
Source File: JapaneseImperialCalendar.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the index to the new era if the given date is in a
 * transition month.  For example, if the give date is Heisei 1
 * (1989) January 20, then the era index for Heisei is
 * returned. Likewise, if the given date is Showa 64 (1989)
 * January 3, then the era index for Heisei is returned. If the
 * given date is not in any transition month, then -1 is returned.
 */
private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) {
    int eraIndex = getEraIndex(date);
    CalendarDate transitionDate = eras[eraIndex].getSinceDate();
    if (transitionDate.getYear() == date.getNormalizedYear() &&
        transitionDate.getMonth() == date.getMonth()) {
        return eraIndex;
    }
    if (eraIndex < eras.length - 1) {
        transitionDate = eras[++eraIndex].getSinceDate();
        if (transitionDate.getYear() == date.getNormalizedYear() &&
            transitionDate.getMonth() == date.getMonth()) {
            return eraIndex;
        }
    }
    return -1;
}
 
Example #13
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 #14
Source File: Time.java    From openjdk-jdk8u-backup 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 #15
Source File: JapaneseImperialCalendar.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the index to the new era if the given date is in a
 * transition month.  For example, if the give date is Heisei 1
 * (1989) January 20, then the era index for Heisei is
 * returned. Likewise, if the given date is Showa 64 (1989)
 * January 3, then the era index for Heisei is returned. If the
 * given date is not in any transition month, then -1 is returned.
 */
private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) {
    int eraIndex = getEraIndex(date);
    CalendarDate transitionDate = eras[eraIndex].getSinceDate();
    if (transitionDate.getYear() == date.getNormalizedYear() &&
        transitionDate.getMonth() == date.getMonth()) {
        return eraIndex;
    }
    if (eraIndex < eras.length - 1) {
        transitionDate = eras[++eraIndex].getSinceDate();
        if (transitionDate.getYear() == date.getNormalizedYear() &&
            transitionDate.getMonth() == date.getMonth()) {
            return eraIndex;
        }
    }
    return -1;
}
 
Example #16
Source File: JapaneseImperialCalendar.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns the index to the new era if the given date is in a
 * transition month.  For example, if the give date is Heisei 1
 * (1989) January 20, then the era index for Heisei is
 * returned. Likewise, if the given date is Showa 64 (1989)
 * January 3, then the era index for Heisei is returned. If the
 * given date is not in any transition month, then -1 is returned.
 */
private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) {
    int eraIndex = getEraIndex(date);
    CalendarDate transitionDate = eras[eraIndex].getSinceDate();
    if (transitionDate.getYear() == date.getNormalizedYear() &&
        transitionDate.getMonth() == date.getMonth()) {
        return eraIndex;
    }
    if (eraIndex < eras.length - 1) {
        transitionDate = eras[++eraIndex].getSinceDate();
        if (transitionDate.getYear() == date.getNormalizedYear() &&
            transitionDate.getMonth() == date.getMonth()) {
            return eraIndex;
        }
    }
    return -1;
}
 
Example #17
Source File: JapaneseImperialCalendar.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the index to the new era if the given date is in a
 * transition month.  For example, if the give date is Heisei 1
 * (1989) January 20, then the era index for Heisei is
 * returned. Likewise, if the given date is Showa 64 (1989)
 * January 3, then the era index for Heisei is returned. If the
 * given date is not in any transition month, then -1 is returned.
 */
private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) {
    int eraIndex = getEraIndex(date);
    CalendarDate transitionDate = eras[eraIndex].getSinceDate();
    if (transitionDate.getYear() == date.getNormalizedYear() &&
        transitionDate.getMonth() == date.getMonth()) {
        return eraIndex;
    }
    if (eraIndex < eras.length - 1) {
        transitionDate = eras[++eraIndex].getSinceDate();
        if (transitionDate.getYear() == date.getNormalizedYear() &&
            transitionDate.getMonth() == date.getMonth()) {
            return eraIndex;
        }
    }
    return -1;
}
 
Example #18
Source File: Time.java    From openjdk-jdk8u 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 #19
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 #20
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 #21
Source File: JapaneseImperialCalendar.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the index to the new era if the given date is in a
 * transition month.  For example, if the give date is Heisei 1
 * (1989) January 20, then the era index for Heisei is
 * returned. Likewise, if the given date is Showa 64 (1989)
 * January 3, then the era index for Heisei is returned. If the
 * given date is not in any transition month, then -1 is returned.
 */
private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) {
    int eraIndex = getEraIndex(date);
    CalendarDate transitionDate = eras[eraIndex].getSinceDate();
    if (transitionDate.getYear() == date.getNormalizedYear() &&
        transitionDate.getMonth() == date.getMonth()) {
        return eraIndex;
    }
    if (eraIndex < eras.length - 1) {
        transitionDate = eras[++eraIndex].getSinceDate();
        if (transitionDate.getYear() == date.getNormalizedYear() &&
            transitionDate.getMonth() == date.getMonth()) {
            return eraIndex;
        }
    }
    return -1;
}
 
Example #22
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 #23
Source File: JapaneseImperialCalendar.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the index to the new era if the given date is in a
 * transition month.  For example, if the give date is Heisei 1
 * (1989) January 20, then the era index for Heisei is
 * returned. Likewise, if the given date is Showa 64 (1989)
 * January 3, then the era index for Heisei is returned. If the
 * given date is not in any transition month, then -1 is returned.
 */
private static int getTransitionEraIndex(LocalGregorianCalendar.Date date) {
    int eraIndex = getEraIndex(date);
    CalendarDate transitionDate = eras[eraIndex].getSinceDate();
    if (transitionDate.getYear() == date.getNormalizedYear() &&
        transitionDate.getMonth() == date.getMonth()) {
        return eraIndex;
    }
    if (eraIndex < eras.length - 1) {
        transitionDate = eras[++eraIndex].getSinceDate();
        if (transitionDate.getYear() == date.getNormalizedYear() &&
            transitionDate.getMonth() == date.getMonth()) {
            return eraIndex;
        }
    }
    return -1;
}
 
Example #24
Source File: JapaneseImperialCalendar.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private int actualMonthLength() {
    int length = jcal.getMonthLength(jdate);
    int eraIndex = getTransitionEraIndex(jdate);
    if (eraIndex == -1) {
        long transitionFixedDate = sinceFixedDates[eraIndex];
        CalendarDate d = eras[eraIndex].getSinceDate();
        if (transitionFixedDate <= cachedFixedDate) {
            length -= d.getDayOfMonth() - 1;
        } else {
            length = d.getDayOfMonth() - 1;
        }
    }
    return length;
}
 
Example #25
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 #26
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 #27
Source File: JapaneseImperialCalendar.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private int actualMonthLength() {
    int length = jcal.getMonthLength(jdate);
    int eraIndex = getTransitionEraIndex(jdate);
    if (eraIndex == -1) {
        long transitionFixedDate = sinceFixedDates[eraIndex];
        CalendarDate d = eras[eraIndex].getSinceDate();
        if (transitionFixedDate <= cachedFixedDate) {
            length -= d.getDayOfMonth() - 1;
        } else {
            length = d.getDayOfMonth() - 1;
        }
    }
    return length;
}
 
Example #28
Source File: JapaneseImperialCalendar.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private int actualMonthLength() {
    int length = jcal.getMonthLength(jdate);
    int eraIndex = getTransitionEraIndex(jdate);
    if (eraIndex == -1) {
        long transitionFixedDate = sinceFixedDates[eraIndex];
        CalendarDate d = eras[eraIndex].getSinceDate();
        if (transitionFixedDate <= cachedFixedDate) {
            length -= d.getDayOfMonth() - 1;
        } else {
            length = d.getDayOfMonth() - 1;
        }
    }
    return length;
}
 
Example #29
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 #30
Source File: JapaneseImperialCalendar.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private int actualMonthLength() {
    int length = jcal.getMonthLength(jdate);
    int eraIndex = getTransitionEraIndex(jdate);
    if (eraIndex == -1) {
        long transitionFixedDate = sinceFixedDates[eraIndex];
        CalendarDate d = eras[eraIndex].getSinceDate();
        if (transitionFixedDate <= cachedFixedDate) {
            length -= d.getDayOfMonth() - 1;
        } else {
            length = d.getDayOfMonth() - 1;
        }
    }
    return length;
}