/** * Gets the <code>TimeZone</code> for the given ID. * * @param ID the ID for a <code>TimeZone</code>, such as "America/Los_Angeles", * or a custom ID such as "GMT-8:00". Note that the support of abbreviations, * such as "PST", is for JDK 1.1.x compatibility only and full names should be used. * * @return the specified <code>TimeZone</code>, or a mutable clone of the UNKNOWN_ZONE * if the given ID cannot be understood or if the given ID is "Etc/Unknown". * @see #UNKNOWN_ZONE * @stable ICU 2.0 */ public static TimeZone getTimeZone(String ID) { return getTimeZone(ID, TZ_IMPL, false); }
/** * Constructs a <code>CECalendar</code> based on the current time * in the default time zone with the given locale. * * @param locale The locale for the new calendar. */ protected CECalendar(ULocale locale) { this(TimeZone.getDefault(), locale); }
/** * Gets the <code>TimeZone</code> for the given ID. The instance of <code>TimeZone</code> * returned by this method is immutable. Any methods mutate the instance({@link #setID(String)}, * {@link #setRawOffset(int)}) will throw <code>UnsupportedOperationException</code> upon its * invocation. * * @param ID the ID for a <code>TimeZone</code>, such as "America/Los_Angeles", * or a custom ID such as "GMT-8:00". Note that the support of abbreviations, * such as "PST", is for JDK 1.1.x compatibility only and full names should be used. * * @return the specified <code>TimeZone</code>, or the UNKNOWN_ZONE * if the given ID cannot be understood. * @see #UNKNOWN_ZONE * @draft ICU 49 * @provisional This API might change or be removed in a future release. */ public static TimeZone getFrozenTimeZone(String ID) { return getTimeZone(ID).freeze(); }
/** * Returns true if this zone has the same rule and offset as another zone. * That is, if this zone differs only in ID, if at all. Returns false * if the other zone is null. * @param other the <code>TimeZone</code> object to be compared with * @return true if the other zone is not null and is the same as this one, * with the possible exception of the ID * @stable ICU 2.0 */ public boolean hasSameRules(TimeZone other) { return other != null && getRawOffset() == other.getRawOffset() && useDaylightTime() == other.useDaylightTime(); }
@Override public long utc(TimeZone tz, long localTime) { com.ibm.icu.util.TimeZone timeZone = toICUTimeZone(tz); long date = localTime - timeZone.getRawOffset(); return localTime - timeZone.getOffset(date); }
private Calendar dateTimeToCalendar(IDateTime dt) { TimeZone tz = dt.isDate() ? TimeZone.getDefault() : TimeZone.getTimeZone(getTZString(dt.getTimezoneOffsetHours(), dt.getTimezoneOffsetMinutes())); Calendar cal = Calendar.getInstance(tz,Locale.getDefault()); cal.setTimeInMillis(dt.getInstant()); return cal; }
@Override public String getDisplayName(TimeZone tz, long date) { com.ibm.icu.util.TimeZone timeZone = toICUTimeZone(tz); int[] offsets = new int[2]; timeZone.getOffset(date, false, offsets); boolean daylightSavings = offsets[1] != 0; if (!daylightSavings && offsets[0] != timeZone.getRawOffset()) { daylightSavings = timeZone.useDaylightTime(); } TimeZoneNames.NameType nameType = daylightSavings ? TimeZoneNames.NameType.SHORT_DAYLIGHT : TimeZoneNames.NameType.SHORT_STANDARD; TimeZoneNames tzNames = TimeZoneNames.getTZDBInstance(ULocale.US); String displayName = tzNames.getDisplayName(timeZone.getID(), nameType, date); if (displayName != null) { return displayName; } return tz.getDisplayName(daylightSavings, TimeZone.SHORT, Locale.US); } }
String[] attempt = TimeZone.getAvailableIDs(getTerritory()); if (attempt.length == 0) { timezoneString = "Etc/GMT"; // gotta do something return TimeZone.getTimeZone(timezoneString);
/** * TimeZone API; calls through to wrapped time zone. */ @Override public int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis) { return zone.getOffset(era, year, month, day, dayOfWeek, millis); }
@Override public String getDisplayName(boolean daylight, int style, Locale locale) { return fIcuTz.getDisplayName(daylight, style, locale); }
@Override public String getID() { return fIcuTz.getID(); }
int offset = daylight ? getRawOffset() + getDSTSavings() : getRawOffset(); result = (style == SHORT_GENERIC) ? tzfmt.formatOffsetShortLocalizedGMT(offset) : tzfmt.formatOffsetLocalizedGMT(offset); int offset = daylight && useDaylightTime() ? getRawOffset() + getDSTSavings() : getRawOffset(); switch (style) { case LONG_GMT: int offset = daylight && useDaylightTime() ? getRawOffset() + getDSTSavings() : getRawOffset(); result = (style == LONG) ? tzfmt.formatOffsetLocalizedGMT(offset) : tzfmt.formatOffsetShortLocalizedGMT(offset);
/** * Gets the <code>TimeZone</code> for the given ID and the timezone type. * @param id time zone ID * @param type time zone implementation type, TIMEZONE_JDK or TIMEZONE_ICU * @param frozen specify if the returned object can be frozen * @return the specified <code>TimeZone</code> or UNKNOWN_ZONE if the given ID * cannot be understood. */ private static TimeZone getTimeZone(String id, int type, boolean frozen) { TimeZone result; if (type == TIMEZONE_JDK) { result = JavaTimeZone.createTimeZone(id); if (result != null) { return frozen ? result.freeze() : result; } result = getFrozenICUTimeZone(id, false); } else { result = getFrozenICUTimeZone(id, true); } if (result == null) { LOGGER.fine("\"" +id + "\" is a bogus id so timezone is falling back to Etc/Unknown(GMT)."); result = UNKNOWN_ZONE; } return frozen ? result : result.cloneAsThawed(); }
String icuID = tz.getID(); jdkZone = java.util.TimeZone.getTimeZone(icuID); if (!icuID.equals(jdkZone.getID())) { icuID = getCanonicalID(icuID); jdkZone = java.util.TimeZone.getTimeZone(icuID); if (!icuID.equals(jdkZone.getID())) {
/** * {@icu} Returns the canonical system time zone ID or the normalized * custom time zone ID for the given time zone ID. * @param id The input time zone ID to be canonicalized. * @return The canonical system time zone ID or the custom time zone ID * in normalized format for the given time zone ID. When the given time zone ID * is neither a known system time zone ID nor a valid custom time zone ID, * null is returned. * @stable ICU 4.0 */ public static String getCanonicalID(String id) { return getCanonicalID(id, null); }
/** * TimeZone API; calls through to wrapped time zone. */ @Override public int getRawOffset() { return zone.getRawOffset(); }
String[] tzIDs = TimeZone.getAvailableIDs(); TimeZoneNames tznames = TimeZoneNames.getInstance(validLocale); tznames.loadAllDisplayNames(); String[][] array = new String[tzIDs.length][5]; for (int i = 0; i < tzIDs.length; i++) { String canonicalID = TimeZone.getCanonicalID(tzIDs[i]); if (canonicalID == null) { canonicalID = tzIDs[i];
tz.getOffset(localMillis, true, offsets); tz.getOffset(localMillis - (24*60*60*1000), true, offsets); resolvedSavings = tz.getDSTSavings();
boolean useStandard = false; int[] offsets = {0, 0}; tz.getOffset(date, false, offsets); tz.getOffset(date - DST_CHECK_RANGE, false, tmpOffsets); if (tmpOffsets[1] != 0) { useStandard = false; } else { tz.getOffset(date + DST_CHECK_RANGE, false, tmpOffsets); if (tmpOffsets[1] != 0){ useStandard = false; TimeZone goldenZone = TimeZone.getFrozenTimeZone(goldenID); int[] offsets1 = {0, 0}; goldenZone.getOffset(date + offsets[0] + offsets[1], true, offsets1);