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