1 11 package com.ibm.icu.impl; 12 import com.ibm.icu.util.TimeZone; 13 import com.ibm.icu.util.SimpleTimeZone; 14 import java.util.Date ; 15 import java.io.IOException ; 16 17 28 public class JDKTimeZone extends TimeZone { 29 30 private static final long serialVersionUID = -3724907649889455280L; 31 32 35 protected transient OlsonTimeZone zone; 37 41 public static TimeZone wrap(java.util.TimeZone tz) { 42 if (tz instanceof TimeZoneAdapter) { 43 return ((TimeZoneAdapter) tz).unwrap(); 44 } 45 if (tz instanceof java.util.SimpleTimeZone ) { 46 return new SimpleTimeZone((java.util.SimpleTimeZone ) tz, tz.getID()); 47 } 48 return new JDKTimeZone(tz); 49 } 50 51 52 60 public JDKTimeZone(java.util.TimeZone tz) { 61 String id = tz.getID(); 62 try{ 63 zone = new OlsonTimeZone(id); 64 }catch(Exception ex){ 65 } 67 super.setID(id); 68 } 69 protected JDKTimeZone(OlsonTimeZone tz) { 70 zone = tz; 71 super.setID(zone.getID()); 72 } 73 76 protected JDKTimeZone() { 77 } 78 83 public void setID(String ID) { 84 super.setID(ID); 85 if(zone!=null){ 86 zone.setID(ID); 87 } 88 } 89 90 93 public int getOffset(int era, int year, int month, int day, 94 int dayOfWeek, int milliseconds) { 95 96 if(zone!=null){ 97 return zone.getOffset(era, year, month, day, 98 dayOfWeek, milliseconds); 99 } 100 return 0; 105 } 106 107 108 public void getOffset(long date, boolean local, int[] offsets) { 109 110 if(zone!=null){ 111 zone.getOffset(date, local, offsets); 112 }else{ 113 super.getOffset(date, local, offsets); 114 } 115 } 116 117 120 public void setRawOffset(int offsetMillis) { 121 if(zone!=null){ 122 zone.setRawOffset(offsetMillis); 123 } 124 } 125 126 129 public int getRawOffset() { 130 if(zone!=null){ 131 return zone.getRawOffset(); 132 } 133 return 0; 138 } 139 140 143 public boolean useDaylightTime() { 144 if(zone!=null){ 145 return zone.useDaylightTime(); 146 } 147 return false; 152 } 153 154 157 public boolean inDaylightTime(Date date) { 158 if(zone!=null){ 159 return zone.inDaylightTime(date); 160 } 161 return false; 166 } 167 168 171 public boolean hasSameRules(TimeZone other) { 172 if (other == null) { 173 return false; 174 } 175 if (other instanceof JDKTimeZone) { 176 if(zone!=null){ 177 return zone.hasSameRules(((JDKTimeZone) other).zone); 178 } 179 } 180 return super.hasSameRules(other); 181 } 182 183 186 public Object clone() { 187 JDKTimeZone clone = new JDKTimeZone(); 188 if(zone!=null){ 189 clone.zone = (OlsonTimeZone)zone.clone(); 190 } 191 return clone; 192 } 193 194 197 public synchronized int hashCode() { 198 if(zone!=null){ 199 return zone.hashCode(); 200 } 201 return super.hashCode(); 202 } 203 204 211 public int getDSTSavings() { 212 if (useDaylightTime()) { 213 if(zone!=null){ 214 return zone.getDSTSavings(); 215 } 216 return 3600000; 217 } 218 return 0; 219 } 220 221 224 public boolean equals(Object obj) { 225 try { 226 if(obj !=null){ 227 TimeZone tz1 = zone; 228 TimeZone tz2 = ((JDKTimeZone) obj).zone; 229 boolean equal = true; 230 if(tz1!=null && tz2!=null){ 231 equal = tz1.equals(tz2); 232 } 233 return equal; 234 } 235 return false; 236 } catch (ClassCastException e) { 237 return false; 238 } 239 } 240 241 245 public String toString() { 246 return "JDKTimeZone: " + zone.toString(); 247 } 248 249 private void writeObject(java.io.ObjectOutputStream out) throws IOException { 250 if(zone!=null){ 251 out.writeObject(zone.getID()); 252 }else{ 253 out.writeObject(getID()); 254 } 255 } 256 257 private void readObject(java.io.ObjectInputStream in) throws IOException , ClassNotFoundException { 258 String id = (String )in.readObject(); 259 260 try{ 262 zone = new OlsonTimeZone(id); 263 }catch(Exception ex){ 264 } 266 setID(id); 267 } 268 } 269 270 | Popular Tags |