Search in sources :

Example 1 with BaseCalendar

use of sun.util.calendar.BaseCalendar in project jdk8u_jdk by JetBrains.

the class Date method toGMTString.

/**
     * Creates a string representation of this <tt>Date</tt> object of
     * the form:
     * <blockquote><pre>
     * d mon yyyy hh:mm:ss GMT</pre></blockquote>
     * where:<ul>
     * <li><i>d</i> is the day of the month (<tt>1</tt> through <tt>31</tt>),
     *     as one or two decimal digits.
     * <li><i>mon</i> is the month (<tt>Jan, Feb, Mar, Apr, May, Jun, Jul,
     *     Aug, Sep, Oct, Nov, Dec</tt>).
     * <li><i>yyyy</i> is the year, as four decimal digits.
     * <li><i>hh</i> is the hour of the day (<tt>00</tt> through <tt>23</tt>),
     *     as two decimal digits.
     * <li><i>mm</i> is the minute within the hour (<tt>00</tt> through
     *     <tt>59</tt>), as two decimal digits.
     * <li><i>ss</i> is the second within the minute (<tt>00</tt> through
     *     <tt>61</tt>), as two decimal digits.
     * <li><i>GMT</i> is exactly the ASCII letters "<tt>GMT</tt>" to indicate
     *     Greenwich Mean Time.
     * </ul><p>
     * The result does not depend on the local time zone.
     *
     * @return  a string representation of this date, using the Internet GMT
     *          conventions.
     * @see     java.text.DateFormat
     * @see     java.util.Date#toString()
     * @see     java.util.Date#toLocaleString()
     * @deprecated As of JDK version 1.1,
     * replaced by <code>DateFormat.format(Date date)</code>, using a
     * GMT <code>TimeZone</code>.
     */
@Deprecated
public String toGMTString() {
    // d MMM yyyy HH:mm:ss 'GMT'
    long t = getTime();
    BaseCalendar cal = getCalendarSystem(t);
    BaseCalendar.Date date = (BaseCalendar.Date) cal.getCalendarDate(getTime(), (TimeZone) null);
    StringBuilder sb = new StringBuilder(32);
    // d
    CalendarUtils.sprintf0d(sb, date.getDayOfMonth(), 1).append(' ');
    // MMM
    convertToAbbr(sb, wtb[date.getMonth() - 1 + 2 + 7]).append(' ');
    // yyyy
    sb.append(date.getYear()).append(' ');
    // HH
    CalendarUtils.sprintf0d(sb, date.getHours(), 2).append(':');
    // mm
    CalendarUtils.sprintf0d(sb, date.getMinutes(), 2).append(':');
    // ss
    CalendarUtils.sprintf0d(sb, date.getSeconds(), 2);
    // ' GMT'
    sb.append(" GMT");
    return sb.toString();
}
Also used : BaseCalendar(sun.util.calendar.BaseCalendar) CalendarDate(sun.util.calendar.CalendarDate) LocalDate(java.time.LocalDate)

Example 2 with BaseCalendar

use of sun.util.calendar.BaseCalendar in project jdk8u_jdk by JetBrains.

the class Date method normalize.

private final BaseCalendar.Date normalize() {
    if (cdate == null) {
        BaseCalendar cal = getCalendarSystem(fastTime);
        cdate = (BaseCalendar.Date) cal.getCalendarDate(fastTime, TimeZone.getDefaultRef());
        return cdate;
    }
    // required for the compatible behavior.
    if (!cdate.isNormalized()) {
        cdate = normalize(cdate);
    }
    // If the default TimeZone has changed, then recalculate the
    // fields with the new TimeZone.
    TimeZone tz = TimeZone.getDefaultRef();
    if (tz != cdate.getZone()) {
        cdate.setZone(tz);
        CalendarSystem cal = getCalendarSystem(cdate);
        cal.getCalendarDate(fastTime, cdate);
    }
    return cdate;
}
Also used : BaseCalendar(sun.util.calendar.BaseCalendar) CalendarSystem(sun.util.calendar.CalendarSystem)

Example 3 with BaseCalendar

use of sun.util.calendar.BaseCalendar in project jdk8u_jdk by JetBrains.

the class GregorianCalendar method getCalendarDate.

/**
     * 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;
}
Also used : BaseCalendar(sun.util.calendar.BaseCalendar) CalendarDate(sun.util.calendar.CalendarDate)

Example 4 with BaseCalendar

use of sun.util.calendar.BaseCalendar in project jdk8u_jdk by JetBrains.

the class GregorianCalendar method computeFields.

/**
     * This computeFields implements the conversion from UTC
     * (millisecond offset from the Epoch) to calendar
     * field values. fieldMask specifies which fields to change the
     * setting state to COMPUTED, although all fields are set to
     * the correct values. This is required to fix 4685354.
     *
     * @param fieldMask a bit mask to specify which fields to change
     * the setting state.
     * @param tzMask a bit mask to specify which time zone offset
     * fields to be used for time calculations
     * @return a new field mask that indicates what field values have
     * actually been set.
     */
private int computeFields(int fieldMask, int tzMask) {
    int zoneOffset = 0;
    TimeZone tz = getZone();
    if (zoneOffsets == null) {
        zoneOffsets = new int[2];
    }
    if (tzMask != (ZONE_OFFSET_MASK | DST_OFFSET_MASK)) {
        if (tz instanceof ZoneInfo) {
            zoneOffset = ((ZoneInfo) tz).getOffsets(time, zoneOffsets);
        } else {
            zoneOffset = tz.getOffset(time);
            zoneOffsets[0] = tz.getRawOffset();
            zoneOffsets[1] = zoneOffset - zoneOffsets[0];
        }
    }
    if (tzMask != 0) {
        if (isFieldSet(tzMask, ZONE_OFFSET)) {
            zoneOffsets[0] = internalGet(ZONE_OFFSET);
        }
        if (isFieldSet(tzMask, DST_OFFSET)) {
            zoneOffsets[1] = internalGet(DST_OFFSET);
        }
        zoneOffset = zoneOffsets[0] + zoneOffsets[1];
    }
    // By computing time and zoneOffset separately, we can take
    // the wider range of time+zoneOffset than the previous
    // implementation.
    long fixedDate = zoneOffset / ONE_DAY;
    int timeOfDay = zoneOffset % (int) ONE_DAY;
    fixedDate += time / ONE_DAY;
    timeOfDay += (int) (time % ONE_DAY);
    if (timeOfDay >= ONE_DAY) {
        timeOfDay -= ONE_DAY;
        ++fixedDate;
    } else {
        while (timeOfDay < 0) {
            timeOfDay += ONE_DAY;
            --fixedDate;
        }
    }
    fixedDate += EPOCH_OFFSET;
    int era = CE;
    int year;
    if (fixedDate >= gregorianCutoverDate) {
        // Handle Gregorian dates.
        assert cachedFixedDate == Long.MIN_VALUE || gdate.isNormalized() : "cache control: not normalized";
        assert cachedFixedDate == Long.MIN_VALUE || gcal.getFixedDate(gdate.getNormalizedYear(), gdate.getMonth(), gdate.getDayOfMonth(), gdate) == cachedFixedDate : "cache control: inconsictency" + ", cachedFixedDate=" + cachedFixedDate + ", computed=" + gcal.getFixedDate(gdate.getNormalizedYear(), gdate.getMonth(), gdate.getDayOfMonth(), gdate) + ", date=" + gdate;
        // See if we can use gdate to avoid date calculation.
        if (fixedDate != cachedFixedDate) {
            gcal.getCalendarDateFromFixedDate(gdate, fixedDate);
            cachedFixedDate = fixedDate;
        }
        year = gdate.getYear();
        if (year <= 0) {
            year = 1 - year;
            era = BCE;
        }
        calsys = gcal;
        cdate = gdate;
        assert cdate.getDayOfWeek() > 0 : "dow=" + cdate.getDayOfWeek() + ", date=" + cdate;
    } else {
        // Handle Julian calendar dates.
        calsys = getJulianCalendarSystem();
        cdate = (BaseCalendar.Date) jcal.newCalendarDate(getZone());
        jcal.getCalendarDateFromFixedDate(cdate, fixedDate);
        Era e = cdate.getEra();
        if (e == jeras[0]) {
            era = BCE;
        }
        year = cdate.getYear();
    }
    // Always set the ERA and YEAR values.
    internalSet(ERA, era);
    internalSet(YEAR, year);
    int mask = fieldMask | (ERA_MASK | YEAR_MASK);
    // 0-based
    int month = cdate.getMonth() - 1;
    int dayOfMonth = cdate.getDayOfMonth();
    // Set the basic date fields.
    if ((fieldMask & (MONTH_MASK | DAY_OF_MONTH_MASK | DAY_OF_WEEK_MASK)) != 0) {
        internalSet(MONTH, month);
        internalSet(DAY_OF_MONTH, dayOfMonth);
        internalSet(DAY_OF_WEEK, cdate.getDayOfWeek());
        mask |= MONTH_MASK | DAY_OF_MONTH_MASK | DAY_OF_WEEK_MASK;
    }
    if ((fieldMask & (HOUR_OF_DAY_MASK | AM_PM_MASK | HOUR_MASK | MINUTE_MASK | SECOND_MASK | MILLISECOND_MASK)) != 0) {
        if (timeOfDay != 0) {
            int hours = timeOfDay / ONE_HOUR;
            internalSet(HOUR_OF_DAY, hours);
            // Assume AM == 0
            internalSet(AM_PM, hours / 12);
            internalSet(HOUR, hours % 12);
            int r = timeOfDay % ONE_HOUR;
            internalSet(MINUTE, r / ONE_MINUTE);
            r %= ONE_MINUTE;
            internalSet(SECOND, r / ONE_SECOND);
            internalSet(MILLISECOND, r % ONE_SECOND);
        } else {
            internalSet(HOUR_OF_DAY, 0);
            internalSet(AM_PM, AM);
            internalSet(HOUR, 0);
            internalSet(MINUTE, 0);
            internalSet(SECOND, 0);
            internalSet(MILLISECOND, 0);
        }
        mask |= (HOUR_OF_DAY_MASK | AM_PM_MASK | HOUR_MASK | MINUTE_MASK | SECOND_MASK | MILLISECOND_MASK);
    }
    if ((fieldMask & (ZONE_OFFSET_MASK | DST_OFFSET_MASK)) != 0) {
        internalSet(ZONE_OFFSET, zoneOffsets[0]);
        internalSet(DST_OFFSET, zoneOffsets[1]);
        mask |= (ZONE_OFFSET_MASK | DST_OFFSET_MASK);
    }
    if ((fieldMask & (DAY_OF_YEAR_MASK | WEEK_OF_YEAR_MASK | WEEK_OF_MONTH_MASK | DAY_OF_WEEK_IN_MONTH_MASK)) != 0) {
        int normalizedYear = cdate.getNormalizedYear();
        long fixedDateJan1 = calsys.getFixedDate(normalizedYear, 1, 1, cdate);
        int dayOfYear = (int) (fixedDate - fixedDateJan1) + 1;
        long fixedDateMonth1 = fixedDate - dayOfMonth + 1;
        int cutoverGap = 0;
        int cutoverYear = (calsys == gcal) ? gregorianCutoverYear : gregorianCutoverYearJulian;
        int relativeDayOfMonth = dayOfMonth - 1;
        // If we are in the cutover year, we need some special handling.
        if (normalizedYear == cutoverYear) {
            // Need to take care of the "missing" days.
            if (gregorianCutoverYearJulian <= gregorianCutoverYear) {
                // We need to find out where we are. The cutover
                // gap could even be more than one year.  (One
                // year difference in ~48667 years.)
                fixedDateJan1 = getFixedDateJan1(cdate, fixedDate);
                if (fixedDate >= gregorianCutoverDate) {
                    fixedDateMonth1 = getFixedDateMonth1(cdate, fixedDate);
                }
            }
            int realDayOfYear = (int) (fixedDate - fixedDateJan1) + 1;
            cutoverGap = dayOfYear - realDayOfYear;
            dayOfYear = realDayOfYear;
            relativeDayOfMonth = (int) (fixedDate - fixedDateMonth1);
        }
        internalSet(DAY_OF_YEAR, dayOfYear);
        internalSet(DAY_OF_WEEK_IN_MONTH, relativeDayOfMonth / 7 + 1);
        int weekOfYear = getWeekNumber(fixedDateJan1, fixedDate);
        // ISO8601-style. This creates problems, though.
        if (weekOfYear == 0) {
            // If the date belongs to the last week of the
            // previous year, use the week number of "12/31" of
            // the "previous" year. Again, if the previous year is
            // the Gregorian cutover year, we need to take care of
            // it.  Usually the previous day of January 1 is
            // December 31, which is not always true in
            // GregorianCalendar.
            long fixedDec31 = fixedDateJan1 - 1;
            long prevJan1 = fixedDateJan1 - 365;
            if (normalizedYear > (cutoverYear + 1)) {
                if (CalendarUtils.isGregorianLeapYear(normalizedYear - 1)) {
                    --prevJan1;
                }
            } else if (normalizedYear <= gregorianCutoverYearJulian) {
                if (CalendarUtils.isJulianLeapYear(normalizedYear - 1)) {
                    --prevJan1;
                }
            } else {
                BaseCalendar calForJan1 = calsys;
                //int prevYear = normalizedYear - 1;
                int prevYear = getCalendarDate(fixedDec31).getNormalizedYear();
                if (prevYear == gregorianCutoverYear) {
                    calForJan1 = getCutoverCalendarSystem();
                    if (calForJan1 == jcal) {
                        prevJan1 = calForJan1.getFixedDate(prevYear, BaseCalendar.JANUARY, 1, null);
                    } else {
                        prevJan1 = gregorianCutoverDate;
                        calForJan1 = gcal;
                    }
                } else if (prevYear <= gregorianCutoverYearJulian) {
                    calForJan1 = getJulianCalendarSystem();
                    prevJan1 = calForJan1.getFixedDate(prevYear, BaseCalendar.JANUARY, 1, null);
                }
            }
            weekOfYear = getWeekNumber(prevJan1, fixedDec31);
        } else {
            if (normalizedYear > gregorianCutoverYear || normalizedYear < (gregorianCutoverYearJulian - 1)) {
                // Regular years
                if (weekOfYear >= 52) {
                    long nextJan1 = fixedDateJan1 + 365;
                    if (cdate.isLeapYear()) {
                        nextJan1++;
                    }
                    long nextJan1st = BaseCalendar.getDayOfWeekDateOnOrBefore(nextJan1 + 6, getFirstDayOfWeek());
                    int ndays = (int) (nextJan1st - nextJan1);
                    if (ndays >= getMinimalDaysInFirstWeek() && fixedDate >= (nextJan1st - 7)) {
                        // The first days forms a week in which the date is included.
                        weekOfYear = 1;
                    }
                }
            } else {
                BaseCalendar calForJan1 = calsys;
                int nextYear = normalizedYear + 1;
                if (nextYear == (gregorianCutoverYearJulian + 1) && nextYear < gregorianCutoverYear) {
                    // In case the gap is more than one year.
                    nextYear = gregorianCutoverYear;
                }
                if (nextYear == gregorianCutoverYear) {
                    calForJan1 = getCutoverCalendarSystem();
                }
                long nextJan1;
                if (nextYear > gregorianCutoverYear || gregorianCutoverYearJulian == gregorianCutoverYear || nextYear == gregorianCutoverYearJulian) {
                    nextJan1 = calForJan1.getFixedDate(nextYear, BaseCalendar.JANUARY, 1, null);
                } else {
                    nextJan1 = gregorianCutoverDate;
                    calForJan1 = gcal;
                }
                long nextJan1st = BaseCalendar.getDayOfWeekDateOnOrBefore(nextJan1 + 6, getFirstDayOfWeek());
                int ndays = (int) (nextJan1st - nextJan1);
                if (ndays >= getMinimalDaysInFirstWeek() && fixedDate >= (nextJan1st - 7)) {
                    // The first days forms a week in which the date is included.
                    weekOfYear = 1;
                }
            }
        }
        internalSet(WEEK_OF_YEAR, weekOfYear);
        internalSet(WEEK_OF_MONTH, getWeekNumber(fixedDateMonth1, fixedDate));
        mask |= (DAY_OF_YEAR_MASK | WEEK_OF_YEAR_MASK | WEEK_OF_MONTH_MASK | DAY_OF_WEEK_IN_MONTH_MASK);
    }
    return mask;
}
Also used : BaseCalendar(sun.util.calendar.BaseCalendar) Era(sun.util.calendar.Era) ZoneInfo(sun.util.calendar.ZoneInfo)

Example 5 with BaseCalendar

use of sun.util.calendar.BaseCalendar in project checker-framework by typetools.

the class Date method parse.

/**
 * Attempts to interpret the string <tt>s</tt> as a representation
 * of a date and time. If the attempt is successful, the time
 * indicated is returned represented as the distance, measured in
 * milliseconds, of that time from the epoch (00:00:00 GMT on
 * January 1, 1970). If the attempt fails, an
 * <tt>IllegalArgumentException</tt> is thrown.
 * <p>
 * It accepts many syntaxes; in particular, it recognizes the IETF
 * standard date syntax: "Sat, 12 Aug 1995 13:30:00 GMT". It also
 * understands the continental U.S. time-zone abbreviations, but for
 * general use, a time-zone offset should be used: "Sat, 12 Aug 1995
 * 13:30:00 GMT+0430" (4 hours, 30 minutes west of the Greenwich
 * meridian). If no time zone is specified, the local time zone is
 * assumed. GMT and UTC are considered equivalent.
 * <p>
 * The string <tt>s</tt> is processed from left to right, looking for
 * data of interest. Any material in <tt>s</tt> that is within the
 * ASCII parenthesis characters <tt>(</tt> and <tt>)</tt> is ignored.
 * Parentheses may be nested. Otherwise, the only characters permitted
 * within <tt>s</tt> are these ASCII characters:
 * <blockquote><pre>
 * abcdefghijklmnopqrstuvwxyz
 * ABCDEFGHIJKLMNOPQRSTUVWXYZ
 * 0123456789,+-:/</pre></blockquote>
 * and whitespace characters.<p>
 * A consecutive sequence of decimal digits is treated as a decimal
 * number:<ul>
 * <li>If a number is preceded by <tt>+</tt> or <tt>-</tt> and a year
 *     has already been recognized, then the number is a time-zone
 *     offset. If the number is less than 24, it is an offset measured
 *     in hours. Otherwise, it is regarded as an offset in minutes,
 *     expressed in 24-hour time format without punctuation. A
 *     preceding <tt>-</tt> means a westward offset. Time zone offsets
 *     are always relative to UTC (Greenwich). Thus, for example,
 *     <tt>-5</tt> occurring in the string would mean "five hours west
 *     of Greenwich" and <tt>+0430</tt> would mean "four hours and
 *     thirty minutes east of Greenwich." It is permitted for the
 *     string to specify <tt>GMT</tt>, <tt>UT</tt>, or <tt>UTC</tt>
 *     redundantly-for example, <tt>GMT-5</tt> or <tt>utc+0430</tt>.
 * <li>The number is regarded as a year number if one of the
 *     following conditions is true:
 * <ul>
 *     <li>The number is equal to or greater than 70 and followed by a
 *         space, comma, slash, or end of string
 *     <li>The number is less than 70, and both a month and a day of
 *         the month have already been recognized</li>
 * </ul>
 *     If the recognized year number is less than 100, it is
 *     interpreted as an abbreviated year relative to a century of
 *     which dates are within 80 years before and 19 years after
 *     the time when the Date class is initialized.
 *     After adjusting the year number, 1900 is subtracted from
 *     it. For example, if the current year is 1999 then years in
 *     the range 19 to 99 are assumed to mean 1919 to 1999, while
 *     years from 0 to 18 are assumed to mean 2000 to 2018.  Note
 *     that this is slightly different from the interpretation of
 *     years less than 100 that is used in {@link java.text.SimpleDateFormat}.
 * <li>If the number is followed by a colon, it is regarded as an hour,
 *     unless an hour has already been recognized, in which case it is
 *     regarded as a minute.
 * <li>If the number is followed by a slash, it is regarded as a month
 *     (it is decreased by 1 to produce a number in the range <tt>0</tt>
 *     to <tt>11</tt>), unless a month has already been recognized, in
 *     which case it is regarded as a day of the month.
 * <li>If the number is followed by whitespace, a comma, a hyphen, or
 *     end of string, then if an hour has been recognized but not a
 *     minute, it is regarded as a minute; otherwise, if a minute has
 *     been recognized but not a second, it is regarded as a second;
 *     otherwise, it is regarded as a day of the month. </ul><p>
 * A consecutive sequence of letters is regarded as a word and treated
 * as follows:<ul>
 * <li>A word that matches <tt>AM</tt>, ignoring case, is ignored (but
 *     the parse fails if an hour has not been recognized or is less
 *     than <tt>1</tt> or greater than <tt>12</tt>).
 * <li>A word that matches <tt>PM</tt>, ignoring case, adds <tt>12</tt>
 *     to the hour (but the parse fails if an hour has not been
 *     recognized or is less than <tt>1</tt> or greater than <tt>12</tt>).
 * <li>Any word that matches any prefix of <tt>SUNDAY, MONDAY, TUESDAY,
 *     WEDNESDAY, THURSDAY, FRIDAY</tt>, or <tt>SATURDAY</tt>, ignoring
 *     case, is ignored. For example, <tt>sat, Friday, TUE</tt>, and
 *     <tt>Thurs</tt> are ignored.
 * <li>Otherwise, any word that matches any prefix of <tt>JANUARY,
 *     FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER,
 *     OCTOBER, NOVEMBER</tt>, or <tt>DECEMBER</tt>, ignoring case, and
 *     considering them in the order given here, is recognized as
 *     specifying a month and is converted to a number (<tt>0</tt> to
 *     <tt>11</tt>). For example, <tt>aug, Sept, april</tt>, and
 *     <tt>NOV</tt> are recognized as months. So is <tt>Ma</tt>, which
 *     is recognized as <tt>MARCH</tt>, not <tt>MAY</tt>.
 * <li>Any word that matches <tt>GMT, UT</tt>, or <tt>UTC</tt>, ignoring
 *     case, is treated as referring to UTC.
 * <li>Any word that matches <tt>EST, CST, MST</tt>, or <tt>PST</tt>,
 *     ignoring case, is recognized as referring to the time zone in
 *     North America that is five, six, seven, or eight hours west of
 *     Greenwich, respectively. Any word that matches <tt>EDT, CDT,
 *     MDT</tt>, or <tt>PDT</tt>, ignoring case, is recognized as
 *     referring to the same time zone, respectively, during daylight
 *     saving time.</ul><p>
 * Once the entire string s has been scanned, it is converted to a time
 * result in one of two ways. If a time zone or time-zone offset has been
 * recognized, then the year, month, day of month, hour, minute, and
 * second are interpreted in UTC and then the time-zone offset is
 * applied. Otherwise, the year, month, day of month, hour, minute, and
 * second are interpreted in the local time zone.
 *
 * @param   s   a string to be parsed as a date.
 * @return  the number of milliseconds since January 1, 1970, 00:00:00 GMT
 *          represented by the string argument.
 * @see     java.text.DateFormat
 * @deprecated As of JDK version 1.1,
 * replaced by <code>DateFormat.parse(String s)</code>.
 */
@Deprecated
public static long parse(String s) {
    int year = Integer.MIN_VALUE;
    int mon = -1;
    int mday = -1;
    int hour = -1;
    int min = -1;
    int sec = -1;
    int millis = -1;
    int c = -1;
    int i = 0;
    int n = -1;
    int wst = -1;
    int tzoffset = -1;
    int prevc = 0;
    syntax: {
        if (s == null)
            break syntax;
        int limit = s.length();
        while (i < limit) {
            c = s.charAt(i);
            i++;
            if (c <= ' ' || c == ',')
                continue;
            if (c == '(') {
                // skip comments
                int depth = 1;
                while (i < limit) {
                    c = s.charAt(i);
                    i++;
                    if (c == '(')
                        depth++;
                    else if (c == ')')
                        if (--depth <= 0)
                            break;
                }
                continue;
            }
            if ('0' <= c && c <= '9') {
                n = c - '0';
                while (i < limit && '0' <= (c = s.charAt(i)) && c <= '9') {
                    n = n * 10 + c - '0';
                    i++;
                }
                if (prevc == '+' || prevc == '-' && year != Integer.MIN_VALUE) {
                    // timezone offset
                    if (n < 24)
                        // EG. "GMT-3"
                        n = n * 60;
                    else
                        // eg "GMT-0430"
                        n = n % 100 + n / 100 * 60;
                    if (// plus means east of GMT
                    prevc == '+')
                        n = -n;
                    if (tzoffset != 0 && tzoffset != -1)
                        break syntax;
                    tzoffset = n;
                } else if (n >= 70)
                    if (year != Integer.MIN_VALUE)
                        break syntax;
                    else if (c <= ' ' || c == ',' || c == '/' || i >= limit)
                        // year = n < 1900 ? n : n - 1900;
                        year = n;
                    else
                        break syntax;
                else if (c == ':')
                    if (hour < 0)
                        hour = (byte) n;
                    else if (min < 0)
                        min = (byte) n;
                    else
                        break syntax;
                else if (c == '/')
                    if (mon < 0)
                        mon = (byte) (n - 1);
                    else if (mday < 0)
                        mday = (byte) n;
                    else
                        break syntax;
                else if (i < limit && c != ',' && c > ' ' && c != '-')
                    break syntax;
                else if (hour >= 0 && min < 0)
                    min = (byte) n;
                else if (min >= 0 && sec < 0)
                    sec = (byte) n;
                else if (mday < 0)
                    mday = (byte) n;
                else // Handle two-digit years < 70 (70-99 handled above).
                if (year == Integer.MIN_VALUE && mon >= 0 && mday >= 0)
                    year = n;
                else
                    break syntax;
                prevc = 0;
            } else if (c == '/' || c == ':' || c == '+' || c == '-')
                prevc = c;
            else {
                int st = i - 1;
                while (i < limit) {
                    c = s.charAt(i);
                    if (!('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z'))
                        break;
                    i++;
                }
                if (i <= st + 1)
                    break syntax;
                int k;
                for (k = wtb.length; --k >= 0; ) if (wtb[k].regionMatches(true, 0, s, st, i - st)) {
                    int action = ttb[k];
                    if (action != 0) {
                        if (action == 1) {
                            // pm
                            if (hour > 12 || hour < 1)
                                break syntax;
                            else if (hour < 12)
                                hour += 12;
                        } else if (action == 14) {
                            // am
                            if (hour > 12 || hour < 1)
                                break syntax;
                            else if (hour == 12)
                                hour = 0;
                        } else if (action <= 13) {
                            // month!
                            if (mon < 0)
                                mon = (byte) (action - 2);
                            else
                                break syntax;
                        } else {
                            tzoffset = action - 10000;
                        }
                    }
                    break;
                }
                if (k < 0)
                    break syntax;
                prevc = 0;
            }
        }
        if (year == Integer.MIN_VALUE || mon < 0 || mday < 0)
            break syntax;
        // Parse 2-digit years within the correct default century.
        if (year < 100) {
            synchronized (Date.class) {
                if (defaultCenturyStart == 0) {
                    defaultCenturyStart = gcal.getCalendarDate().getYear() - 80;
                }
            }
            year += (defaultCenturyStart / 100) * 100;
            if (year < defaultCenturyStart)
                year += 100;
        }
        if (sec < 0)
            sec = 0;
        if (min < 0)
            min = 0;
        if (hour < 0)
            hour = 0;
        BaseCalendar cal = getCalendarSystem(year);
        if (tzoffset == -1) {
            // no time zone specified, have to use local
            BaseCalendar.Date ldate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
            ldate.setDate(year, mon + 1, mday);
            ldate.setTimeOfDay(hour, min, sec, 0);
            return cal.getTime(ldate);
        }
        // no time zone
        BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null);
        udate.setDate(year, mon + 1, mday);
        udate.setTimeOfDay(hour, min, sec, 0);
        return cal.getTime(udate) + tzoffset * (60 * 1000);
    }
    // syntax error
    throw new IllegalArgumentException();
}
Also used : BaseCalendar(sun.util.calendar.BaseCalendar) CalendarDate(sun.util.calendar.CalendarDate)

Aggregations

BaseCalendar (sun.util.calendar.BaseCalendar)44 CalendarDate (sun.util.calendar.CalendarDate)20 CalendarSystem (sun.util.calendar.CalendarSystem)8 LocalDate (java.time.LocalDate)6 Era (sun.util.calendar.Era)4 ZoneInfo (sun.util.calendar.ZoneInfo)3 NativeTimeZone (com.google.j2objc.util.NativeTimeZone)1