-//##header\r
-/*\r
- *******************************************************************************\r
- * Copyright (C) 2008-2009, International Business Machines Corporation and *\r
- * others. All Rights Reserved. *\r
- *******************************************************************************\r
- */\r
-package com.ibm.icu.impl;\r
-\r
-import java.io.IOException;\r
-import java.io.ObjectInputStream;\r
-import java.util.Date;\r
-import java.util.TreeSet;\r
-\r
-import com.ibm.icu.util.TimeZone;\r
-\r
-/**\r
- * JavaTimeZone inherits com.ibm.icu.util.TimeZone and wraps java.util.TimeZone.\r
- * We used to have JDKTimeZone which wrapped Java TimeZone and used it as primary\r
- * TimeZone implementation until ICU4J 3.4.1. This class works exactly like\r
- * JDKTimeZone and allows ICU users who use ICU4J and JDK date/time/calendar\r
- * services in mix to maintain only JDK timezone rules.\r
- *\r
- * This TimeZone subclass is returned by the TimeZone factory method getTimeZone(String)\r
- * when the default timezone type in TimeZone class is TimeZone.TIMEZONE_JDK.\r
- */\r
-public class JavaTimeZone extends TimeZone {\r
-\r
- private static final long serialVersionUID = 6977448185543929364L;\r
-\r
- private static final TreeSet AVAILABLESET;\r
-\r
- private java.util.TimeZone javatz;\r
- private transient java.util.Calendar javacal;\r
-\r
- static {\r
- AVAILABLESET = new TreeSet();\r
- String[] availableIds = java.util.TimeZone.getAvailableIDs();\r
- for (int i = 0; i < availableIds.length; i++) {\r
- AVAILABLESET.add(availableIds[i]);\r
- }\r
- }\r
-\r
- /**\r
- * Constructs a JavaTimeZone with the default Java TimeZone\r
- */\r
- public JavaTimeZone() {\r
- javatz = java.util.TimeZone.getDefault();\r
- setID(javatz.getID());\r
- javacal = new java.util.GregorianCalendar(javatz);\r
- }\r
-\r
- /**\r
- * Constructs a JavaTimeZone with the given timezone ID.\r
- * @param id A timezone ID, either a system ID or a custom ID.\r
- */\r
- public JavaTimeZone(String id) {\r
- if (AVAILABLESET.contains(id)) {\r
- javatz = java.util.TimeZone.getTimeZone(id);\r
- }\r
- if (javatz == null) {\r
- // Use ICU's canonical ID mapping\r
- boolean[] isSystemID = new boolean[1];\r
- String canonicalID = TimeZone.getCanonicalID(id, isSystemID);\r
- if (isSystemID[0] && AVAILABLESET.contains(canonicalID)) {\r
- javatz = java.util.TimeZone.getTimeZone(canonicalID);\r
- }\r
- }\r
-\r
- if (javatz == null){\r
- int[] fields = new int[4];\r
- if (ZoneMeta.parseCustomID(id, fields)) {\r
- // JDK does not support offset seconds.\r
- // If custom ID, we create java.util.SimpleTimeZone here.\r
- id = ZoneMeta.formatCustomID(fields[1], fields[2], fields[3], fields[0] < 0);\r
- int offset = fields[0] * ((fields[1] * 60 + fields[2]) * 60 + fields[3]) * 1000;\r
- javatz = new java.util.SimpleTimeZone(offset, id);\r
- }\r
- }\r
- if (javatz == null) {\r
- // Final fallback\r
- id = "GMT";\r
- javatz = java.util.TimeZone.getTimeZone(id);\r
- }\r
- setID(id);\r
- javacal = new java.util.GregorianCalendar(javatz);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.ibm.icu.util.TimeZone#getOffset(int, int, int, int, int, int)\r
- */\r
- public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds) {\r
- return javatz.getOffset(era, year, month, day, dayOfWeek, milliseconds);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.ibm.icu.util.TimeZone#getOffset(long, boolean, int[])\r
- */\r
- public void getOffset(long date, boolean local, int[] offsets) {\r
- synchronized (javacal) {\r
- if (local) {\r
- int fields[] = new int[6];\r
- Grego.timeToFields(date, fields);\r
- int hour, min, sec, mil;\r
- int tmp = fields[5];\r
- mil = tmp % 1000;\r
- tmp /= 1000;\r
- sec = tmp % 60;\r
- tmp /= 60;\r
- min = tmp % 60;\r
- hour = tmp / 60;\r
- javacal.clear();\r
- javacal.set(fields[0], fields[1], fields[2], hour, min, sec);\r
- javacal.set(java.util.Calendar.MILLISECOND, mil);\r
-\r
- int doy1, hour1, min1, sec1, mil1;\r
- doy1 = javacal.get(java.util.Calendar.DAY_OF_YEAR);\r
- hour1 = javacal.get(java.util.Calendar.HOUR_OF_DAY);\r
- min1 = javacal.get(java.util.Calendar.MINUTE);\r
- sec1 = javacal.get(java.util.Calendar.SECOND);\r
- mil1 = javacal.get(java.util.Calendar.MILLISECOND);\r
-\r
- if (fields[4] != doy1 || hour != hour1 || min != min1 || sec != sec1 || mil != mil1) {\r
- // Calendar field(s) were changed due to the adjustment for non-existing time\r
- // Note: This code does not support non-existing local time at year boundary properly.\r
- // But, it should work fine for real timezones.\r
- int dayDelta = Math.abs(doy1 - fields[4]) > 1 ? 1 : doy1 - fields[4];\r
- int delta = ((((dayDelta * 24) + hour1 - hour) * 60 + min1 - min) * 60 + sec1 - sec) * 1000 + mil1 - mil;\r
-\r
- // In this case, we use the offsets before the transition\r
-//#if defined(FOUNDATION10) || defined(J2SE13)\r
-//## javacal.setTime(new Date(javacal.getTime().getTime() - delta - 1));\r
-//#else\r
- javacal.setTimeInMillis(javacal.getTimeInMillis() - delta - 1);\r
-//#endif\r
- }\r
- } else {\r
-//#if defined(FOUNDATION10) || defined(J2SE13)\r
-//## javacal.setTime(new Date(date));\r
-//#else\r
- javacal.setTimeInMillis(date);\r
-//#endif\r
- }\r
- offsets[0] = javacal.get(java.util.Calendar.ZONE_OFFSET);\r
- offsets[1] = javacal.get(java.util.Calendar.DST_OFFSET);\r
- }\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.ibm.icu.util.TimeZone#getRawOffset()\r
- */\r
- public int getRawOffset() {\r
- return javatz.getRawOffset();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.ibm.icu.util.TimeZone#inDaylightTime(java.util.Date)\r
- */\r
- public boolean inDaylightTime(Date date) {\r
- return javatz.inDaylightTime(date);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.ibm.icu.util.TimeZone#setRawOffset(int)\r
- */\r
- public void setRawOffset(int offsetMillis) {\r
- javatz.setRawOffset(offsetMillis);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.ibm.icu.util.TimeZone#useDaylightTime()\r
- */\r
- public boolean useDaylightTime() {\r
- return javatz.useDaylightTime();\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.ibm.icu.util.TimeZone#getDSTSavings()\r
- */\r
- public int getDSTSavings() {\r
- int dstSavings = super.getDSTSavings();\r
- try {\r
- // hack so test compiles and runs in both JDK 1.3 and JDK 1.4+\r
- final Object[] args = new Object[0];\r
- final Class[] argtypes = new Class[0];\r
- java.lang.reflect.Method m = javatz.getClass().getMethod("getDSTSavings", argtypes); \r
- dstSavings = ((Integer) m.invoke(javatz, args)).intValue();\r
- } catch (Exception e) {\r
- // just use the result returned by super.getDSTSavings()\r
- }\r
- return dstSavings;\r
- }\r
-\r
- public java.util.TimeZone unwrap() {\r
- return javatz;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.ibm.icu.util.TimeZone#clone()\r
- */\r
- public Object clone() {\r
- JavaTimeZone other = (JavaTimeZone)super.clone();\r
- other.javatz = (java.util.TimeZone)javatz.clone();\r
- return other;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.ibm.icu.util.TimeZone#hashCode()\r
- */\r
- public int hashCode() {\r
- return super.hashCode() + javatz.hashCode();\r
- }\r
-\r
- private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {\r
- s.defaultReadObject();\r
- javacal = new java.util.GregorianCalendar(javatz);\r
- }\r
-\r
-}\r
+//##header J2SE15
+/*
+ *******************************************************************************
+ * Copyright (C) 2008-2009, International Business Machines Corporation and *
+ * others. All Rights Reserved. *
+ *******************************************************************************
+ */
+package com.ibm.icu.impl;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.util.Date;
+import java.util.TreeSet;
+
+import com.ibm.icu.util.TimeZone;
+
+/**
+ * JavaTimeZone inherits com.ibm.icu.util.TimeZone and wraps java.util.TimeZone.
+ * We used to have JDKTimeZone which wrapped Java TimeZone and used it as primary
+ * TimeZone implementation until ICU4J 3.4.1. This class works exactly like
+ * JDKTimeZone and allows ICU users who use ICU4J and JDK date/time/calendar
+ * services in mix to maintain only JDK timezone rules.
+ *
+ * This TimeZone subclass is returned by the TimeZone factory method getTimeZone(String)
+ * when the default timezone type in TimeZone class is TimeZone.TIMEZONE_JDK.
+ */
+public class JavaTimeZone extends TimeZone {
+
+ private static final long serialVersionUID = 6977448185543929364L;
+
+ private static final TreeSet AVAILABLESET;
+
+ private java.util.TimeZone javatz;
+ private transient java.util.Calendar javacal;
+
+ static {
+ AVAILABLESET = new TreeSet();
+ String[] availableIds = java.util.TimeZone.getAvailableIDs();
+ for (int i = 0; i < availableIds.length; i++) {
+ AVAILABLESET.add(availableIds[i]);
+ }
+ }
+
+ /**
+ * Constructs a JavaTimeZone with the default Java TimeZone
+ */
+ public JavaTimeZone() {
+ javatz = java.util.TimeZone.getDefault();
+ setID(javatz.getID());
+ javacal = new java.util.GregorianCalendar(javatz);
+ }
+
+ /**
+ * Constructs a JavaTimeZone with the given timezone ID.
+ * @param id A timezone ID, either a system ID or a custom ID.
+ */
+ public JavaTimeZone(String id) {
+ if (AVAILABLESET.contains(id)) {
+ javatz = java.util.TimeZone.getTimeZone(id);
+ }
+ if (javatz == null) {
+ // Use ICU's canonical ID mapping
+ boolean[] isSystemID = new boolean[1];
+ String canonicalID = TimeZone.getCanonicalID(id, isSystemID);
+ if (isSystemID[0] && AVAILABLESET.contains(canonicalID)) {
+ javatz = java.util.TimeZone.getTimeZone(canonicalID);
+ }
+ }
+
+ if (javatz == null){
+ int[] fields = new int[4];
+ if (ZoneMeta.parseCustomID(id, fields)) {
+ // JDK does not support offset seconds.
+ // If custom ID, we create java.util.SimpleTimeZone here.
+ id = ZoneMeta.formatCustomID(fields[1], fields[2], fields[3], fields[0] < 0);
+ int offset = fields[0] * ((fields[1] * 60 + fields[2]) * 60 + fields[3]) * 1000;
+ javatz = new java.util.SimpleTimeZone(offset, id);
+ }
+ }
+ if (javatz == null) {
+ // Final fallback
+ id = "GMT";
+ javatz = java.util.TimeZone.getTimeZone(id);
+ }
+ setID(id);
+ javacal = new java.util.GregorianCalendar(javatz);
+ }
+
+ /* (non-Javadoc)
+ * @see com.ibm.icu.util.TimeZone#getOffset(int, int, int, int, int, int)
+ */
+ public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds) {
+ return javatz.getOffset(era, year, month, day, dayOfWeek, milliseconds);
+ }
+
+ /* (non-Javadoc)
+ * @see com.ibm.icu.util.TimeZone#getOffset(long, boolean, int[])
+ */
+ public void getOffset(long date, boolean local, int[] offsets) {
+ synchronized (javacal) {
+ if (local) {
+ int fields[] = new int[6];
+ Grego.timeToFields(date, fields);
+ int hour, min, sec, mil;
+ int tmp = fields[5];
+ mil = tmp % 1000;
+ tmp /= 1000;
+ sec = tmp % 60;
+ tmp /= 60;
+ min = tmp % 60;
+ hour = tmp / 60;
+ javacal.clear();
+ javacal.set(fields[0], fields[1], fields[2], hour, min, sec);
+ javacal.set(java.util.Calendar.MILLISECOND, mil);
+
+ int doy1, hour1, min1, sec1, mil1;
+ doy1 = javacal.get(java.util.Calendar.DAY_OF_YEAR);
+ hour1 = javacal.get(java.util.Calendar.HOUR_OF_DAY);
+ min1 = javacal.get(java.util.Calendar.MINUTE);
+ sec1 = javacal.get(java.util.Calendar.SECOND);
+ mil1 = javacal.get(java.util.Calendar.MILLISECOND);
+
+ if (fields[4] != doy1 || hour != hour1 || min != min1 || sec != sec1 || mil != mil1) {
+ // Calendar field(s) were changed due to the adjustment for non-existing time
+ // Note: This code does not support non-existing local time at year boundary properly.
+ // But, it should work fine for real timezones.
+ int dayDelta = Math.abs(doy1 - fields[4]) > 1 ? 1 : doy1 - fields[4];
+ int delta = ((((dayDelta * 24) + hour1 - hour) * 60 + min1 - min) * 60 + sec1 - sec) * 1000 + mil1 - mil;
+
+ // In this case, we use the offsets before the transition
+//#if defined(FOUNDATION10) || defined(J2SE13)
+//## javacal.setTime(new Date(javacal.getTime().getTime() - delta - 1));
+//#else
+ javacal.setTimeInMillis(javacal.getTimeInMillis() - delta - 1);
+//#endif
+ }
+ } else {
+//#if defined(FOUNDATION10) || defined(J2SE13)
+//## javacal.setTime(new Date(date));
+//#else
+ javacal.setTimeInMillis(date);
+//#endif
+ }
+ offsets[0] = javacal.get(java.util.Calendar.ZONE_OFFSET);
+ offsets[1] = javacal.get(java.util.Calendar.DST_OFFSET);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.ibm.icu.util.TimeZone#getRawOffset()
+ */
+ public int getRawOffset() {
+ return javatz.getRawOffset();
+ }
+
+ /* (non-Javadoc)
+ * @see com.ibm.icu.util.TimeZone#inDaylightTime(java.util.Date)
+ */
+ public boolean inDaylightTime(Date date) {
+ return javatz.inDaylightTime(date);
+ }
+
+ /* (non-Javadoc)
+ * @see com.ibm.icu.util.TimeZone#setRawOffset(int)
+ */
+ public void setRawOffset(int offsetMillis) {
+ javatz.setRawOffset(offsetMillis);
+ }
+
+ /* (non-Javadoc)
+ * @see com.ibm.icu.util.TimeZone#useDaylightTime()
+ */
+ public boolean useDaylightTime() {
+ return javatz.useDaylightTime();
+ }
+
+ /* (non-Javadoc)
+ * @see com.ibm.icu.util.TimeZone#getDSTSavings()
+ */
+ public int getDSTSavings() {
+ int dstSavings = super.getDSTSavings();
+ try {
+ // hack so test compiles and runs in both JDK 1.3 and JDK 1.4+
+ final Object[] args = new Object[0];
+ final Class[] argtypes = new Class[0];
+ java.lang.reflect.Method m = javatz.getClass().getMethod("getDSTSavings", argtypes);
+ dstSavings = ((Integer) m.invoke(javatz, args)).intValue();
+ } catch (Exception e) {
+ // just use the result returned by super.getDSTSavings()
+ }
+ return dstSavings;
+ }
+
+ public java.util.TimeZone unwrap() {
+ return javatz;
+ }
+
+ /* (non-Javadoc)
+ * @see com.ibm.icu.util.TimeZone#clone()
+ */
+ public Object clone() {
+ JavaTimeZone other = (JavaTimeZone)super.clone();
+ other.javatz = (java.util.TimeZone)javatz.clone();
+ return other;
+ }
+
+ /* (non-Javadoc)
+ * @see com.ibm.icu.util.TimeZone#hashCode()
+ */
+ public int hashCode() {
+ return super.hashCode() + javatz.hashCode();
+ }
+
+ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
+ s.defaultReadObject();
+ javacal = new java.util.GregorianCalendar(javatz);
+ }
+
+}