sun.util.calendar.CalendarSystem Java Examples

The following examples show how to use sun.util.calendar.CalendarSystem. 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: SimpleTimeZone.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see TimeZone#getOffsets
 */
int getOffsets(long date, int[] offsets) {
    int offset = rawOffset;

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

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

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

    if (offsets != null) {
        offsets[0] = rawOffset;
        offsets[1] = offset - rawOffset;
    }
    return offset;
}
 
Example #3
Source File: SimpleTimeZone.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see TimeZone#getOffsets
 */
int getOffsets(long date, int[] offsets) {
    int offset = rawOffset;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if (offsets != null) {
        offsets[0] = rawOffset;
        offsets[1] = offset - rawOffset;
    }
    return offset;
}
 
Example #14
Source File: CalendarNameProviderImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) {
    String name = null;
    String key = getResourceKey(calendarType, field, style, javatime);
    if (key != null) {
        LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
        String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
        if (strings != null && strings.length > 0) {
            if (field == DAY_OF_WEEK || field == YEAR) {
                --value;
            }
            if (value < 0 || value > strings.length) {
                return null;
            } else if (value == strings.length) {
                if (field == ERA && "japanese".equals(calendarType)) {
                    // get the supplemental era, if any, specified through
                    // the property "jdk.calendar.japanese.supplemental.era"
                    // which is always the last element.
                    Era[] jeras = CalendarSystem.forName("japanese").getEras();
                    if (jeras.length == value) {
                        Era supEra = jeras[value - 1]; // 0-based index
                        return style == LONG ?
                            supEra.getName() :
                            supEra.getAbbreviation();
                    }
                }
                return null;
            }
            name = strings[value];
            // If name is empty in standalone, try its `format' style.
            if (name.length() == 0
                    && (style == SHORT_STANDALONE || style == LONG_STANDALONE
                        || style == NARROW_STANDALONE)) {
                name = getDisplayName(calendarType, field, value,
                                      getBaseStyle(style),
                                      locale);
            }
        }
    }
    return name;
}
 
Example #15
Source File: SimpleTimeZone.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see TimeZone#getOffsets
 */
int getOffsets(long date, int[] offsets) {
    int offset = rawOffset;

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

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

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

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

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

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

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

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

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

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

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

    if (offsets != null) {
        offsets[0] = rawOffset;
        offsets[1] = offset - rawOffset;
    }
    return offset;
}
 
Example #21
Source File: CalendarNameProviderImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) {
    String name = null;
    String key = getResourceKey(calendarType, field, style, javatime);
    if (key != null) {
        LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
        String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);

        // If standalone names are requested and no "standalone." resources are found,
        // try the default ones instead.
        if (strings == null && key.indexOf("standalone.") != -1) {
            key = key.replaceFirst("standalone.", "");
            strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
        }

        if (strings != null && strings.length > 0) {
            if (field == DAY_OF_WEEK || field == YEAR) {
                --value;
            }
            if (value < 0) {
                return null;
            } else if (value >= strings.length) {
                if (field == ERA && "japanese".equals(calendarType)) {
                    Era[] jeras = CalendarSystem.forName("japanese").getEras();
                    if (value <= jeras.length) {
                        // Localized era name could not be retrieved from this provider.
                        // This can occur either for Reiwa or SupEra.
                        //
                        // If it's CLDR provider, try COMPAT first, which is guaranteed to have
                        // the name for Reiwa.
                        if (type == LocaleProviderAdapter.Type.CLDR) {
                            lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
                            key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE,
                                            calendarType, field, style, javatime);
                            strings =
                                javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
                        }
                        if (strings == null || value >= strings.length) {
                            // Get the default name for SupEra
                            Era supEra = jeras[value - 1]; // 0-based index
                            if (javatime) {
                                return getBaseStyle(style) == NARROW_FORMAT ?
                                    supEra.getAbbreviation() :
                                    supEra.getName();
                            } else {
                                return (style & LONG) != 0 ?
                                    supEra.getName() :
                                    supEra.getAbbreviation();
                            }
                        }
                    } else {
                        return null;
                    }
                } else {
                    return null;
                }
            }
            name = strings[value];
            // If name is empty in standalone, try its `format' style.
            if (name.isEmpty()
                    && (style == SHORT_STANDALONE || style == LONG_STANDALONE
                        || style == NARROW_STANDALONE)) {
                name = getDisplayName(calendarType, field, value,
                                      getBaseStyle(style),
                                      locale);
            }
        }
    }
    return name;
}
 
Example #22
Source File: CalendarNameProviderImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) {
    String name = null;
    String key = getResourceKey(calendarType, field, style, javatime);
    if (key != null) {
        LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
        String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);

        // If standalone names are requested and no "standalone." resources are found,
        // try the default ones instead.
        if (strings == null && key.indexOf("standalone.") != -1) {
            key = key.replaceFirst("standalone.", "");
            strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
        }

        if (strings != null && strings.length > 0) {
            if (field == DAY_OF_WEEK || field == YEAR) {
                --value;
            }
            if (value < 0 || value > strings.length) {
                return null;
            } else if (value == strings.length) {
                if (field == ERA && "japanese".equals(calendarType)) {
                    // get the supplemental era, if any, specified through
                    // the property "jdk.calendar.japanese.supplemental.era"
                    // which is always the last element.
                    Era[] jeras = CalendarSystem.forName("japanese").getEras();
                    if (jeras.length == value) {
                        Era supEra = jeras[value - 1]; // 0-based index
                        return style == LONG ?
                            supEra.getName() :
                            supEra.getAbbreviation();
                    }
                }
                return null;
            }
            name = strings[value];
            // If name is empty in standalone, try its `format' style.
            if (name.length() == 0
                    && (style == SHORT_STANDALONE || style == LONG_STANDALONE
                        || style == NARROW_STANDALONE)) {
                name = getDisplayName(calendarType, field, value,
                                      getBaseStyle(style),
                                      locale);
            }
        }
    }
    return name;
}
 
Example #23
Source File: CalendarNameProviderImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) {
    String name = null;
    String key = getResourceKey(calendarType, field, style, javatime);
    if (key != null) {
        LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
        String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
        if (strings != null && strings.length > 0) {
            if (field == DAY_OF_WEEK || field == YEAR) {
                --value;
            }
            if (value < 0) {
                return null;
            } else if (value >= strings.length) {
                if (field == ERA && "japanese".equals(calendarType)) {
                    Era[] jeras = CalendarSystem.forName("japanese").getEras();
                    if (value <= jeras.length) {
                        // Localized era name could not be retrieved from this provider.
                        // This can occur either for Reiwa or SupEra.
                        //
                        // If it's CLDR provider, try COMPAT first, which is guaranteed to have
                        // the name for Reiwa.
                        if (type == LocaleProviderAdapter.Type.CLDR) {
                            lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
                            key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE,
                                            calendarType, field, style, javatime);
                            strings =
                                javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
                        }
                        if (strings == null || value >= strings.length) {
                            // Get the default name for SupEra
                        Era supEra = jeras[value - 1]; // 0-based index
                            if (javatime) {
                                return getBaseStyle(style) == NARROW_FORMAT ?
                                    supEra.getAbbreviation() :
                                    supEra.getName();
                            } else {
                                return (style & LONG) != 0 ?
                            supEra.getName() :
                            supEra.getAbbreviation();
                    }
                }
                    } else {
                return null;
            }
                } else {
                    return null;
                }
            }
            name = strings[value];
            // If name is empty in standalone, try its `format' style.
            if (name.length() == 0
                    && (style == SHORT_STANDALONE || style == LONG_STANDALONE
                        || style == NARROW_STANDALONE)) {
                name = getDisplayName(calendarType, field, value,
                                      getBaseStyle(style),
                                      locale);
            }
        }
    }
    return name;
}
 
Example #24
Source File: CalendarNameProviderImpl.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) {
    String name = null;
    String key = getResourceKey(calendarType, field, style, javatime);
    if (key != null) {
        LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
        String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
        if (strings != null && strings.length > 0) {
            if (field == DAY_OF_WEEK || field == YEAR) {
                --value;
            }
            if (value < 0) {
                return null;
            } else if (value >= strings.length) {
                if (field == ERA && "japanese".equals(calendarType)) {
                    Era[] jeras = CalendarSystem.forName("japanese").getEras();
                    if (value <= jeras.length) {
                        // Localized era name could not be retrieved from this provider.
                        // This can occur either for Reiwa or SupEra.
                        //
                        // If it's CLDR provider, try COMPAT first, which is guaranteed to have
                        // the name for Reiwa.
                        if (type == LocaleProviderAdapter.Type.CLDR) {
                            lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
                            key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE,
                                            calendarType, field, style, javatime);
                            strings =
                                javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
                        }
                        if (strings == null || value >= strings.length) {
                            // Get the default name for SupEra
                        Era supEra = jeras[value - 1]; // 0-based index
                            if (javatime) {
                                return getBaseStyle(style) == NARROW_FORMAT ?
                                    supEra.getAbbreviation() :
                                    supEra.getName();
                            } else {
                                return (style & LONG) != 0 ?
                            supEra.getName() :
                            supEra.getAbbreviation();
                    }
                }
                    } else {
                return null;
            }
                } else {
                    return null;
                }
            }
            name = strings[value];
            // If name is empty in standalone, try its `format' style.
            if (name.length() == 0
                    && (style == SHORT_STANDALONE || style == LONG_STANDALONE
                        || style == NARROW_STANDALONE)) {
                name = getDisplayName(calendarType, field, value,
                                      getBaseStyle(style),
                                      locale);
            }
        }
    }
    return name;
}
 
Example #25
Source File: CalendarNameProviderImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) {
    String name = null;
    String key = getResourceKey(calendarType, field, style, javatime);
    if (key != null) {
        LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
        String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
        if (strings != null && strings.length > 0) {
            if (field == DAY_OF_WEEK || field == YEAR) {
                --value;
            }
            if (value < 0) {
                return null;
            } else if (value >= strings.length) {
                if (field == ERA && "japanese".equals(calendarType)) {
                    Era[] jeras = CalendarSystem.forName("japanese").getEras();
                    if (value <= jeras.length) {
                        // Localized era name could not be retrieved from this provider.
                        // This can occur either for Reiwa or SupEra.
                        //
                        // If it's CLDR provider, try COMPAT first, which is guaranteed to have
                        // the name for Reiwa.
                        if (type == LocaleProviderAdapter.Type.CLDR) {
                            lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
                            key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE,
                                            calendarType, field, style, javatime);
                            strings =
                                javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
                        }
                        if (strings == null || value >= strings.length) {
                            // Get the default name for SupEra
                        Era supEra = jeras[value - 1]; // 0-based index
                            if (javatime) {
                                return getBaseStyle(style) == NARROW_FORMAT ?
                                    supEra.getAbbreviation() :
                                    supEra.getName();
                            } else {
                                return (style & LONG) != 0 ?
                            supEra.getName() :
                            supEra.getAbbreviation();
                    }
                }
                    } else {
                return null;
            }
                } else {
                    return null;
                }
            }
            name = strings[value];
            // If name is empty in standalone, try its `format' style.
            if (name.length() == 0
                    && (style == SHORT_STANDALONE || style == LONG_STANDALONE
                        || style == NARROW_STANDALONE)) {
                name = getDisplayName(calendarType, field, value,
                                      getBaseStyle(style),
                                      locale);
            }
        }
    }
    return name;
}
 
Example #26
Source File: CalendarNameProviderImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public String getDisplayNameImpl(String calendarType, int field, int value, int style, Locale locale, boolean javatime) {
    String name = null;
    String key = getResourceKey(calendarType, field, style, javatime);
    if (key != null) {
        LocaleResources lr = LocaleProviderAdapter.forType(type).getLocaleResources(locale);
        String[] strings = javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
        if (strings != null && strings.length > 0) {
            if (field == DAY_OF_WEEK || field == YEAR) {
                --value;
            }
            if (value < 0) {
                return null;
            } else if (value >= strings.length) {
                if (field == ERA && "japanese".equals(calendarType)) {
                    Era[] jeras = CalendarSystem.forName("japanese").getEras();
                    if (value <= jeras.length) {
                        // Localized era name could not be retrieved from this provider.
                        // This can occur either for Reiwa or SupEra.
                        //
                        // If it's CLDR provider, try COMPAT first, which is guaranteed to have
                        // the name for Reiwa.
                        if (type == LocaleProviderAdapter.Type.CLDR) {
                            lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
                            key = getResourceKeyFor(LocaleProviderAdapter.Type.JRE,
                                            calendarType, field, style, javatime);
                            strings =
                                javatime ? lr.getJavaTimeNames(key) : lr.getCalendarNames(key);
                        }
                        if (strings == null || value >= strings.length) {
                            // Get the default name for SupEra
                        Era supEra = jeras[value - 1]; // 0-based index
                            if (javatime) {
                                return getBaseStyle(style) == NARROW_FORMAT ?
                                    supEra.getAbbreviation() :
                                    supEra.getName();
                            } else {
                                return (style & LONG) != 0 ?
                            supEra.getName() :
                            supEra.getAbbreviation();
                    }
                }
                    } else {
                return null;
            }
                } else {
                    return null;
                }
            }
            name = strings[value];
            // If name is empty in standalone, try its `format' style.
            if (name.length() == 0
                    && (style == SHORT_STANDALONE || style == LONG_STANDALONE
                        || style == NARROW_STANDALONE)) {
                name = getDisplayName(calendarType, field, value,
                                      getBaseStyle(style),
                                      locale);
            }
        }
    }
    return name;
}