1/*
2*******************************************************************************
3* Copyright (C) 2007-2008, International Business Machines Corporation and         *
4* others. All Rights Reserved.                                                *
5*******************************************************************************
6*/
7#ifndef TZTRANS_H
8#define TZTRANS_H
9
10/**
11 * \file
12 * \brief C++ API: Time zone transition
13 */
14
15#include "unicode/utypes.h"
16
17#if !UCONFIG_NO_FORMATTING
18
19#include "unicode/uobject.h"
20
21U_NAMESPACE_BEGIN
22
23// Forward declaration
24class TimeZoneRule;
25
26/**
27 * <code>TimeZoneTransition</code> is a class representing a time zone transition.
28 * An instance has a time of transition and rules for both before and after the transition.
29 * @stable ICU 3.8
30 */
31class U_I18N_API TimeZoneTransition : public UObject {
32public:
33    /**
34     * Constructs a <code>TimeZoneTransition</code> with the time and the rules before/after
35     * the transition.
36     *
37     * @param time  The time of transition in milliseconds since the base time.
38     * @param from  The time zone rule used before the transition.
39     * @param to    The time zone rule used after the transition.
40     * @stable ICU 3.8
41     */
42    TimeZoneTransition(UDate time, const TimeZoneRule& from, const TimeZoneRule& to);
43
44    /**
45     * Constructs an empty <code>TimeZoneTransition</code>
46     * @stable ICU 3.8
47     */
48    TimeZoneTransition();
49
50    /**
51     * Copy constructor.
52     * @param source    The TimeZoneTransition object to be copied.
53     * @stable ICU 3.8
54     */
55    TimeZoneTransition(const TimeZoneTransition& source);
56
57    /**
58     * Destructor.
59     * @stable ICU 3.8
60     */
61    ~TimeZoneTransition();
62
63    /**
64     * Clone this TimeZoneTransition object polymorphically. The caller owns the result and
65     * should delete it when done.
66     * @return  A copy of the object.
67     * @stable ICU 3.8
68     */
69    TimeZoneTransition* clone(void) const;
70
71    /**
72     * Assignment operator.
73     * @param right The object to be copied.
74     * @stable ICU 3.8
75     */
76    TimeZoneTransition& operator=(const TimeZoneTransition& right);
77
78    /**
79     * Return true if the given TimeZoneTransition objects are semantically equal. Objects
80     * of different subclasses are considered unequal.
81     * @param that  The object to be compared with.
82     * @return  true if the given TimeZoneTransition objects are semantically equal.
83     * @stable ICU 3.8
84     */
85    UBool operator==(const TimeZoneTransition& that) const;
86
87    /**
88     * Return true if the given TimeZoneTransition objects are semantically unequal. Objects
89     * of different subclasses are considered unequal.
90     * @param that  The object to be compared with.
91     * @return  true if the given TimeZoneTransition objects are semantically unequal.
92     * @stable ICU 3.8
93     */
94    UBool operator!=(const TimeZoneTransition& that) const;
95
96    /**
97     * Returns the time of transition in milliseconds.
98     * @return The time of the transition in milliseconds since the 1970 Jan 1 epoch time.
99     * @stable ICU 3.8
100     */
101    UDate getTime(void) const;
102
103    /**
104     * Sets the time of transition in milliseconds.
105     * @param time The time of the transition in milliseconds since the 1970 Jan 1 epoch time.
106     * @stable ICU 3.8
107     */
108    void setTime(UDate time);
109
110    /**
111     * Returns the rule used before the transition.
112     * @return The time zone rule used after the transition.
113     * @stable ICU 3.8
114     */
115    const TimeZoneRule* getFrom(void) const;
116
117    /**
118     * Sets the rule used before the transition.  The caller remains
119     * responsible for deleting the <code>TimeZoneRule</code> object.
120     * @param from The time zone rule used before the transition.
121     * @stable ICU 3.8
122     */
123    void setFrom(const TimeZoneRule& from);
124
125    /**
126     * Adopts the rule used before the transition.  The caller must
127     * not delete the <code>TimeZoneRule</code> object passed in.
128     * @param from The time zone rule used before the transition.
129     * @stable ICU 3.8
130     */
131    void adoptFrom(TimeZoneRule* from);
132
133    /**
134     * Sets the rule used after the transition.  The caller remains
135     * responsible for deleting the <code>TimeZoneRule</code> object.
136     * @param to The time zone rule used after the transition.
137     * @stable ICU 3.8
138     */
139    void setTo(const TimeZoneRule& to);
140
141    /**
142     * Adopts the rule used after the transition.  The caller must
143     * not delete the <code>TimeZoneRule</code> object passed in.
144     * @param to The time zone rule used after the transition.
145     * @stable ICU 3.8
146     */
147    void adoptTo(TimeZoneRule* to);
148
149    /**
150     * Returns the rule used after the transition.
151     * @return The time zone rule used after the transition.
152     * @stable ICU 3.8
153     */
154    const TimeZoneRule* getTo(void) const;
155
156private:
157    UDate   fTime;
158    TimeZoneRule*   fFrom;
159    TimeZoneRule*   fTo;
160
161public:
162    /**
163     * Return the class ID for this class. This is useful only for comparing to
164     * a return value from getDynamicClassID(). For example:
165     * <pre>
166     * .   Base* polymorphic_pointer = createPolymorphicObject();
167     * .   if (polymorphic_pointer->getDynamicClassID() ==
168     * .       erived::getStaticClassID()) ...
169     * </pre>
170     * @return          The class ID for all objects of this class.
171     * @stable ICU 3.8
172     */
173    static UClassID U_EXPORT2 getStaticClassID(void);
174
175    /**
176     * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
177     * method is to implement a simple version of RTTI, since not all C++
178     * compilers support genuine RTTI. Polymorphic operator==() and clone()
179     * methods call this method.
180     *
181     * @return          The class ID for this object. All objects of a
182     *                  given class have the same class ID.  Objects of
183     *                  other classes have different class IDs.
184     * @stable ICU 3.8
185     */
186    virtual UClassID getDynamicClassID(void) const;
187};
188
189U_NAMESPACE_END
190
191#endif /* #if !UCONFIG_NO_FORMATTING */
192
193#endif // TZTRANS_H
194
195//eof
196