ICU-7521 Merging fixes for ticket#7535(r27817) and ticket#7542(r27830) from trunk to maint-4-4 for ICU4J 4.4 release.

X-SVN-Rev: 27831
diff --git a/main/classes/core/src/com/ibm/icu/impl/JavaTimeZone.java b/main/classes/core/src/com/ibm/icu/impl/JavaTimeZone.java
index bcdcc2e..021aa8e 100644
--- a/main/classes/core/src/com/ibm/icu/impl/JavaTimeZone.java
+++ b/main/classes/core/src/com/ibm/icu/impl/JavaTimeZone.java
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 2008-2009, International Business Machines Corporation and    *
+ * Copyright (C) 2008-2010, International Business Machines Corporation and    *
  * others. All Rights Reserved.                                                *
  *******************************************************************************
  */
@@ -9,7 +9,6 @@
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.util.Date;
-import java.util.GregorianCalendar;
 import java.util.TreeSet;
 
 import com.ibm.icu.util.TimeZone;
@@ -31,7 +30,8 @@
     private static final TreeSet<String> AVAILABLESET;
 
     private java.util.TimeZone javatz;
-    
+    private transient java.util.Calendar javacal;
+
     static {
         AVAILABLESET = new TreeSet<String>();
         String[] availableIds = java.util.TimeZone.getAvailableIDs();
@@ -46,6 +46,7 @@
     public JavaTimeZone() {
         javatz = java.util.TimeZone.getDefault();
         setID(javatz.getID());
+        javacal = new java.util.GregorianCalendar(javatz);
     }
 
     /**
@@ -81,6 +82,7 @@
             javatz = java.util.TimeZone.getTimeZone(id);
         }
         setID(id);
+        javacal = new java.util.GregorianCalendar(javatz);
     }
 
     /* (non-Javadoc)
@@ -94,32 +96,45 @@
      * @see com.ibm.icu.util.TimeZone#getOffset(long, boolean, int[])
      */
     public void getOffset(long date, boolean local, int[] offsets) {
-        int offset;
-        int dstOffset = 0;
-        
-        if (local) {
-            int fields[] = new int[6];
-            Grego.timeToFields(date, fields);
-            
-            int era = GregorianCalendar.AD;
-            int year = fields[0];
-            if (year <= 0) {
-                era = GregorianCalendar.BC;
-                year = 1 - year;
+        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
+                   javacal.setTimeInMillis(javacal.getTimeInMillis() - delta - 1);
+                }
+            } else {
+                javacal.setTimeInMillis(date);
             }
-            
-            offset = javatz.getOffset(era, year, fields[1], fields[2], fields[3], fields[5]);
-            
-        } else {
-            offset = javatz.getOffset(date);
+            offsets[0] = javacal.get(java.util.Calendar.ZONE_OFFSET);
+            offsets[1] = javacal.get(java.util.Calendar.DST_OFFSET);
         }
-        
-        if (javatz.inDaylightTime(new Date(date))) {
-            dstOffset = javatz.getDSTSavings();
-        }
-        
-        offsets[0] = offset - dstOffset;
-        offsets[1] = dstOffset;
     }
 
     /* (non-Javadoc)
@@ -189,5 +204,6 @@
 
     private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
         s.defaultReadObject();
+        javacal = new java.util.GregorianCalendar(javatz);
     }
 }
diff --git a/main/shared/licenses/license.html b/main/shared/licenses/license.html
index ba2871a..7ae0252 100644
--- a/main/shared/licenses/license.html
+++ b/main/shared/licenses/license.html
@@ -11,7 +11,7 @@
 <p>COPYRIGHT AND PERMISSION NOTICE</p>
 
 <p>
-Copyright (c) 1995-2009 International Business Machines Corporation and others
+Copyright (c) 1995-2010 International Business Machines Corporation and others
 </p>
 <p>
 All rights reserved.
diff --git a/main/shared/licenses/unicode-license.txt b/main/shared/licenses/unicode-license.txt
index cf5cfdb..900059f 100644
--- a/main/shared/licenses/unicode-license.txt
+++ b/main/shared/licenses/unicode-license.txt
@@ -16,7 +16,7 @@
 
     COPYRIGHT AND PERMISSION NOTICE
 
-    Copyright © 1991-2008 Unicode, Inc. All rights reserved. Distributed under
+    Copyright © 1991-2009 Unicode, Inc. All rights reserved. Distributed under
 the Terms of Use in http://www.unicode.org/copyright.html.
 
     Permission is hereby granted, free of charge, to any person obtaining a copy