2 **********************************************************************
3 * Copyright (c) 2003-2010, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
7 * Created: October 2 2003
9 **********************************************************************
12 package com.ibm.icu.impl;
13 import java.util.Date;
15 import com.ibm.icu.util.TimeZone;
18 * <code>TimeZoneAdapter</code> wraps a com.ibm.icu.util.TimeZone
19 * subclass and inherits from java.util.TimeZone.
20 * Without this class, we would need to 'port' java.util.Date to
21 * com.ibm.icu.util as well, so that Date could interoperate properly
22 * with the com.ibm.icu.util TimeZone and Calendar classes. With this
23 * class, we can use java.util.Date together with com.ibm.icu.util
26 * @see com.ibm.icu.util.TimeZone#setDefault
30 public class TimeZoneAdapter extends java.util.TimeZone {
32 // Generated by serialver from JDK 1.4.1_01
33 static final long serialVersionUID = -2040072218820018557L;
36 * The contained com.ibm.icu.util.TimeZone object. Must not be null.
37 * We delegate all methods to this object.
39 private TimeZone zone;
42 * Given a java.util.TimeZone, wrap it in the appropriate adapter
43 * subclass of com.ibm.icu.util.TimeZone and return the adapter.
45 public static java.util.TimeZone wrap(com.ibm.icu.util.TimeZone tz) {
46 return new TimeZoneAdapter(tz);
50 * Return the java.util.TimeZone wrapped by this object.
52 public com.ibm.icu.util.TimeZone unwrap() {
57 * Constructs an adapter for a com.ibm.icu.util.TimeZone object.
59 public TimeZoneAdapter(TimeZone zone) {
61 super.setID(zone.getID());
65 * TimeZone API; calls through to wrapped time zone.
67 public void setID(String ID) {
73 * TimeZone API; calls through to wrapped time zone.
75 public boolean hasSameRules(java.util.TimeZone other) {
76 return other instanceof TimeZoneAdapter &&
77 zone.hasSameRules(((TimeZoneAdapter)other).zone);
81 * TimeZone API; calls through to wrapped time zone.
83 public int getOffset(int era, int year, int month, int day, int dayOfWeek,
85 return zone.getOffset(era, year, month, day, dayOfWeek, millis);
89 * TimeZone API; calls through to wrapped time zone.
91 public int getRawOffset() {
92 return zone.getRawOffset();
96 * TimeZone API; calls through to wrapped time zone.
98 public void setRawOffset(int offsetMillis) {
99 zone.setRawOffset(offsetMillis);
103 * TimeZone API; calls through to wrapped time zone.
105 public boolean useDaylightTime() {
106 return zone.useDaylightTime();
110 * TimeZone API; calls through to wrapped time zone.
112 public boolean inDaylightTime(Date date) {
113 return zone.inDaylightTime(date);
117 * Boilerplate API; calls through to wrapped object.
119 public Object clone() {
120 return new TimeZoneAdapter((TimeZone)zone.clone());
124 * Boilerplate API; calls through to wrapped object.
126 public synchronized int hashCode() {
127 return zone.hashCode();
131 * Boilerplate API; calls through to wrapped object.
133 public boolean equals(Object obj) {
134 if (obj instanceof TimeZoneAdapter) {
135 obj = ((TimeZoneAdapter) obj).zone;
137 return zone.equals(obj);
141 * Returns a string representation of this object.
142 * @return a string representation of this object.
144 public String toString() {
145 return "TimeZoneAdapter: " + zone.toString();