/*
**********************************************************************
-* Copyright (c) 2003-2014 International Business Machines
+* Copyright (c) 2003-2015 International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Author: Alan Liu
* Returns a frozen OlsonTimeZone instance for the given ID.
* This method returns null when the given ID is unknown.
*/
- public static TimeZone getSystemTimeZone(String id) {
+ public static OlsonTimeZone getSystemTimeZone(String id) {
return SYSTEM_ZONE_CACHE.getInstance(id, id);
}
* @return a frozen SimpleTimeZone with the given offset and
* no Daylight Savings Time, or null if the id cannot be parsed.
*/
- public static TimeZone getCustomTimeZone(String id){
+ public static SimpleTimeZone getCustomTimeZone(String id){
int[] fields = new int[4];
if (parseCustomID(id, fields)) {
// fields[0] - sign
* @param offset GMT offset in milliseconds
* @return A custom TimeZone for the offset with normalized time zone id
*/
- public static TimeZone getCustomTimeZone(int offset) {
+ public static SimpleTimeZone getCustomTimeZone(int offset) {
boolean negative = false;
int tmp = offset;
if (offset < 0) {
/**
* Gets the <code>TimeZone</code> for the given ID and the timezone type.
- * @param ID time zone ID
+ * @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) {
+ private static TimeZone getTimeZone(String id, int type, boolean frozen) {
TimeZone result;
if (type == TIMEZONE_JDK) {
- result = JavaTimeZone.createTimeZone(ID);
+ result = JavaTimeZone.createTimeZone(id);
if (result != null) {
return frozen ? result.freeze() : result;
- }
+ }
+ result = getFrozenICUTimeZone(id, false);
} else {
- /* We first try to lookup the zone ID in our system list. If this
- * fails, we try to parse it as a custom string GMT[+-]HH:mm. If
- * all else fails, we return GMT, which is probably not what the
- * user wants, but at least is a functioning TimeZone object.
- *
- * We cannot return NULL, because that would break compatibility
- * with the JDK.
- */
- if(ID==null){
- throw new NullPointerException();
- }
- result = ZoneMeta.getSystemTimeZone(ID);
- }
-
- if (result == null) {
- result = ZoneMeta.getCustomTimeZone(ID);
+ result = getFrozenICUTimeZone(id, true);
}
-
if (result == null) {
- LOGGER.fine("\"" +ID + "\" is a bogus id so timezone is falling back to Etc/Unknown(GMT).");
+ LOGGER.fine("\"" +id + "\" is a bogus id so timezone is falling back to Etc/Unknown(GMT).");
result = UNKNOWN_ZONE;
}
-
return frozen ? result : result.cloneAsThawed();
}
+
+ /**
+ * Returns a frozen ICU type TimeZone object given a time zone ID.
+ * @param id the time zone ID
+ * @param trySystem if true tries the system time zones first otherwise skip to the
+ * custom time zones.
+ * @return the frozen ICU TimeZone or null if one could not be created.
+ */
+ static BasicTimeZone getFrozenICUTimeZone(String id, boolean trySystem) {
+ BasicTimeZone result = null;
+ if (trySystem) {
+ result = ZoneMeta.getSystemTimeZone(id);
+ }
+ if (result == null) {
+ result = ZoneMeta.getCustomTimeZone(id);
+ }
+ return result;
+ }
/**
* Sets the default time zone type used by <code>getTimeZone</code>.
/*
*******************************************************************************
- * Copyright (C) 2007-2014, International Business Machines Corporation and *
+ * Copyright (C) 2007-2015, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
* @stable ICU 3.8
*/
public static VTimeZone create(String tzid) {
+ BasicTimeZone basicTimeZone = TimeZone.getFrozenICUTimeZone(tzid, true);
+ if (basicTimeZone == null) {
+ return null;
+ }
VTimeZone vtz = new VTimeZone(tzid);
- vtz.tz = (BasicTimeZone)TimeZone.getTimeZone(tzid, TimeZone.TIMEZONE_ICU);
+ vtz.tz = (BasicTimeZone) basicTimeZone.cloneAsThawed();
vtz.olsonzid = vtz.tz.getID();
return vtz;