1// © 2016 and later: Unicode, Inc. and others. 2// License & terms of use: http://www.unicode.org/copyright.html#License 3/* 4 ******************************************************************************* 5 * Copyright (C) 2008, International Business Machines Corporation and * 6 * others. All Rights Reserved. * 7 ******************************************************************************* 8 */ 9package com.ibm.icu.impl.jdkadapter; 10 11import java.util.Date; 12import java.util.Locale; 13 14import com.ibm.icu.impl.icuadapter.TimeZoneJDK; 15import com.ibm.icu.util.TimeZone; 16 17/** 18 * TimeZoneICU is an adapter class which wraps ICU4J TimeZone and 19 * implements java.util.TimeZone APIs. 20 */ 21public class TimeZoneICU extends java.util.TimeZone { 22 23 private static final long serialVersionUID = 6019030618408620277L; 24 25 private TimeZone fIcuTz; 26 27 private TimeZoneICU(TimeZone icuTz) { 28 fIcuTz = icuTz; 29 } 30 31 public static java.util.TimeZone wrap(TimeZone icuTz) { 32 if (icuTz instanceof TimeZoneJDK) { 33 return ((TimeZoneJDK)icuTz).unwrap(); 34 } 35 return new TimeZoneICU(icuTz); 36 } 37 38 public TimeZone unwrap() { 39 return fIcuTz; 40 } 41 42 @Override 43 public Object clone() { 44 TimeZoneICU other = (TimeZoneICU)super.clone(); 45 other.fIcuTz = (TimeZone)fIcuTz.clone(); 46 return other; 47 } 48 49 //public String getDisplayName() 50 //public String getDisplayName(boolean daylight, int style) 51 //public String getDisplayName(Locale locale) 52 53 @Override 54 public String getDisplayName(boolean daylight, int style, Locale locale) { 55 return fIcuTz.getDisplayName(daylight, style, locale); 56 } 57 58 @Override 59 public int getDSTSavings() { 60 return fIcuTz.getDSTSavings(); 61 } 62 63 @Override 64 public String getID() { 65 return fIcuTz.getID(); 66 } 67 68 @Override 69 public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds) { 70 return fIcuTz.getOffset(era, year, month, day, dayOfWeek, milliseconds); 71 } 72 73 @Override 74 public int getOffset(long date) { 75 return fIcuTz.getOffset(date); 76 } 77 78 @Override 79 public int getRawOffset() { 80 return fIcuTz.getRawOffset(); 81 } 82 83 @Override 84 public boolean hasSameRules(java.util.TimeZone other) { 85 return other.hasSameRules(TimeZoneICU.wrap(fIcuTz)); 86 } 87 88 @Override 89 public boolean inDaylightTime(Date date) { 90 return fIcuTz.inDaylightTime(date); 91 } 92 93 @Override 94 public void setID(String ID) { 95 fIcuTz.setID(ID); 96 } 97 98 @Override 99 public void setRawOffset(int offsetMillis) { 100 fIcuTz.setRawOffset(offsetMillis); 101 } 102 103 @Override 104 public boolean useDaylightTime() { 105 return fIcuTz.useDaylightTime(); 106 } 107} 108