michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 2007-2013, International Business Machines Corporation and michael@0: * others. All Rights Reserved. michael@0: ******************************************************************************* michael@0: */ michael@0: #ifndef BASICTZ_H michael@0: #define BASICTZ_H michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: ICU TimeZone base class michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/timezone.h" michael@0: #include "unicode/tzrule.h" michael@0: #include "unicode/tztrans.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: // forward declarations michael@0: class UVector; michael@0: michael@0: /** michael@0: * BasicTimeZone is an abstract class extending TimeZone. michael@0: * This class provides some additional methods to access time zone transitions and rules. michael@0: * All ICU TimeZone concrete subclasses extend this class. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: class U_I18N_API BasicTimeZone: public TimeZone { michael@0: public: michael@0: /** michael@0: * Destructor. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: virtual ~BasicTimeZone(); michael@0: michael@0: /** michael@0: * Gets the first time zone transition after the base time. michael@0: * @param base The base time. michael@0: * @param inclusive Whether the base time is inclusive or not. michael@0: * @param result Receives the first transition after the base time. michael@0: * @return TRUE if the transition is found. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const = 0; michael@0: michael@0: /** michael@0: * Gets the most recent time zone transition before the base time. michael@0: * @param base The base time. michael@0: * @param inclusive Whether the base time is inclusive or not. michael@0: * @param result Receives the most recent transition before the base time. michael@0: * @return TRUE if the transition is found. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const = 0; michael@0: michael@0: /** michael@0: * Checks if the time zone has equivalent transitions in the time range. michael@0: * This method returns true when all of transition times, from/to standard michael@0: * offsets and DST savings used by this time zone match the other in the michael@0: * time range. michael@0: * @param tz The BasicTimeZone object to be compared with. michael@0: * @param start The start time of the evaluated time range (inclusive) michael@0: * @param end The end time of the evaluated time range (inclusive) michael@0: * @param ignoreDstAmount michael@0: * When true, any transitions with only daylight saving amount michael@0: * changes will be ignored, except either of them is zero. michael@0: * For example, a transition from rawoffset 3:00/dstsavings 1:00 michael@0: * to rawoffset 2:00/dstsavings 2:00 is excluded from the comparison, michael@0: * but a transtion from rawoffset 2:00/dstsavings 1:00 to michael@0: * rawoffset 3:00/dstsavings 0:00 is included. michael@0: * @param ec Output param to filled in with a success or an error. michael@0: * @return true if the other time zone has the equivalent transitions in the michael@0: * time range. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: virtual UBool hasEquivalentTransitions(const BasicTimeZone& tz, UDate start, UDate end, michael@0: UBool ignoreDstAmount, UErrorCode& ec) const; michael@0: michael@0: /** michael@0: * Returns the number of TimeZoneRules which represents time transitions, michael@0: * for this time zone, that is, all TimeZoneRules for this time zone except michael@0: * InitialTimeZoneRule. The return value range is 0 or any positive value. michael@0: * @param status Receives error status code. michael@0: * @return The number of TimeZoneRules representing time transitions. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: virtual int32_t countTransitionRules(UErrorCode& status) const = 0; michael@0: michael@0: /** michael@0: * Gets the InitialTimeZoneRule and the set of TimeZoneRule michael@0: * which represent time transitions for this time zone. On successful return, michael@0: * the argument initial points to non-NULL InitialTimeZoneRule and michael@0: * the array trsrules is filled with 0 or multiple TimeZoneRule michael@0: * instances up to the size specified by trscount. The results are referencing the michael@0: * rule instance held by this time zone instance. Therefore, after this time zone michael@0: * is destructed, they are no longer available. michael@0: * @param initial Receives the initial timezone rule michael@0: * @param trsrules Receives the timezone transition rules michael@0: * @param trscount On input, specify the size of the array 'transitions' receiving michael@0: * the timezone transition rules. On output, actual number of michael@0: * rules filled in the array will be set. michael@0: * @param status Receives error status code. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial, michael@0: const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const = 0; michael@0: michael@0: /** michael@0: * Gets the set of time zone rules valid at the specified time. Some known external time zone michael@0: * implementations are not capable to handle historic time zone rule changes. Also some michael@0: * implementations can only handle certain type of rule definitions. michael@0: * If this time zone does not use any daylight saving time within about 1 year from the specified michael@0: * time, only the InitialTimeZone is returned. Otherwise, the rule for standard michael@0: * time and daylight saving time transitions are returned in addition to the michael@0: * InitialTimeZoneRule. The standard and daylight saving time transition rules are michael@0: * represented by AnnualTimeZoneRule with DateTimeRule::DOW for its date michael@0: * rule and DateTimeRule::WALL_TIME for its time rule. Because daylight saving time michael@0: * rule is changing time to time in many time zones and also mapping a transition time rule to michael@0: * different type is lossy transformation, the set of rules returned by this method may be valid michael@0: * for short period of time. michael@0: * The time zone rule objects returned by this method is owned by the caller, so the caller is michael@0: * responsible for deleting them after use. michael@0: * @param date The date used for extracting time zone rules. michael@0: * @param initial Receives the InitialTimeZone, always not NULL. michael@0: * @param std Receives the AnnualTimeZoneRule for standard time transitions. michael@0: * When this time time zone does not observe daylight saving times around the michael@0: * specified date, NULL is set. michael@0: * @param dst Receives the AnnualTimeZoneRule for daylight saving time michael@0: * transitions. When this time zone does not observer daylight saving times michael@0: * around the specified date, NULL is set. michael@0: * @param status Receives error status code. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: virtual void getSimpleRulesNear(UDate date, InitialTimeZoneRule*& initial, michael@0: AnnualTimeZoneRule*& std, AnnualTimeZoneRule*& dst, UErrorCode& status) const; michael@0: michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * The time type option bit flags used by getOffsetFromLocal michael@0: * @internal michael@0: */ michael@0: enum { michael@0: kStandard = 0x01, michael@0: kDaylight = 0x03, michael@0: kFormer = 0x04, michael@0: kLatter = 0x0C michael@0: }; michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: /** michael@0: * Get time zone offsets from local wall time. michael@0: * @internal michael@0: */ michael@0: virtual void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt, michael@0: int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const; michael@0: michael@0: protected: michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * The time type option bit masks used by getOffsetFromLocal michael@0: * @internal michael@0: */ michael@0: enum { michael@0: kStdDstMask = kDaylight, michael@0: kFormerLatterMask = kLatter michael@0: }; michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: /** michael@0: * Default constructor. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: BasicTimeZone(); michael@0: michael@0: /** michael@0: * Construct a timezone with a given ID. michael@0: * @param id a system time zone ID michael@0: * @stable ICU 3.8 michael@0: */ michael@0: BasicTimeZone(const UnicodeString &id); michael@0: michael@0: /** michael@0: * Copy constructor. michael@0: * @param source the object to be copied. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: BasicTimeZone(const BasicTimeZone& source); michael@0: michael@0: /** michael@0: * Gets the set of TimeZoneRule instances applicable to the specified time and after. michael@0: * @param start The start date used for extracting time zone rules michael@0: * @param initial Receives the InitialTimeZone, always not NULL michael@0: * @param transitionRules Receives the transition rules, could be NULL michael@0: * @param status Receives error status code michael@0: */ michael@0: void getTimeZoneRulesAfter(UDate start, InitialTimeZoneRule*& initial, UVector*& transitionRules, michael@0: UErrorCode& status) const; michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif // BASICTZ_H michael@0: michael@0: //eof