Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/unicode/basictz.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004 *******************************************************************************
0005 * Copyright (C) 2007-2013, International Business Machines Corporation and
0006 * others. All Rights Reserved.
0007 *******************************************************************************
0008 */
0009 #ifndef BASICTZ_H
0010 #define BASICTZ_H
0011 
0012 /**
0013  * \file 
0014  * \brief C++ API: ICU TimeZone base class
0015  */
0016 
0017 #include "unicode/utypes.h"
0018 
0019 #if U_SHOW_CPLUSPLUS_API
0020 
0021 #if !UCONFIG_NO_FORMATTING
0022 
0023 #include "unicode/timezone.h"
0024 #include "unicode/tzrule.h"
0025 #include "unicode/tztrans.h"
0026 
0027 U_NAMESPACE_BEGIN
0028 
0029 // forward declarations
0030 class UVector;
0031 
0032 /**
0033  * <code>BasicTimeZone</code> is an abstract class extending <code>TimeZone</code>.
0034  * This class provides some additional methods to access time zone transitions and rules.
0035  * All ICU <code>TimeZone</code> concrete subclasses extend this class.
0036  * @stable ICU 3.8
0037  */
0038 class U_I18N_API BasicTimeZone: public TimeZone {
0039 public:
0040     /**
0041      * Destructor.
0042      * @stable ICU 3.8
0043      */
0044     virtual ~BasicTimeZone();
0045 
0046     /**
0047      * Clones this object polymorphically.
0048      * The caller owns the result and should delete it when done.
0049      * @return clone, or nullptr if an error occurred
0050      * @stable ICU 3.8
0051      */
0052     virtual BasicTimeZone* clone() const override = 0;
0053 
0054     /**
0055      * Gets the first time zone transition after the base time.
0056      * @param base      The base time.
0057      * @param inclusive Whether the base time is inclusive or not.
0058      * @param result    Receives the first transition after the base time.
0059      * @return  true if the transition is found.
0060      * @stable ICU 3.8
0061      */
0062     virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const = 0;
0063 
0064     /**
0065      * Gets the most recent time zone transition before the base time.
0066      * @param base      The base time.
0067      * @param inclusive Whether the base time is inclusive or not.
0068      * @param result    Receives the most recent transition before the base time.
0069      * @return  true if the transition is found.
0070      * @stable ICU 3.8
0071      */
0072     virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const = 0;
0073 
0074     /**
0075      * Checks if the time zone has equivalent transitions in the time range.
0076      * This method returns true when all of transition times, from/to standard
0077      * offsets and DST savings used by this time zone match the other in the
0078      * time range.
0079      * @param tz    The <code>BasicTimeZone</code> object to be compared with.
0080      * @param start The start time of the evaluated time range (inclusive)
0081      * @param end   The end time of the evaluated time range (inclusive)
0082      * @param ignoreDstAmount
0083      *              When true, any transitions with only daylight saving amount
0084      *              changes will be ignored, except either of them is zero.
0085      *              For example, a transition from rawoffset 3:00/dstsavings 1:00
0086      *              to rawoffset 2:00/dstsavings 2:00 is excluded from the comparison,
0087      *              but a transition from rawoffset 2:00/dstsavings 1:00 to
0088      *              rawoffset 3:00/dstsavings 0:00 is included.
0089      * @param ec    Output param to filled in with a success or an error.
0090      * @return      true if the other time zone has the equivalent transitions in the
0091      *              time range.
0092      * @stable ICU 3.8
0093      */
0094     virtual UBool hasEquivalentTransitions(const BasicTimeZone& tz, UDate start, UDate end,
0095         UBool ignoreDstAmount, UErrorCode& ec) const;
0096 
0097     /**
0098      * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
0099      * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
0100      * <code>InitialTimeZoneRule</code>.  The return value range is 0 or any positive value.
0101      * @param status    Receives error status code.
0102      * @return The number of <code>TimeZoneRule</code>s representing time transitions.
0103      * @stable ICU 3.8
0104      */
0105     virtual int32_t countTransitionRules(UErrorCode& status) const = 0;
0106 
0107     /**
0108      * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
0109      * which represent time transitions for this time zone.  On successful return,
0110      * the argument initial points to non-nullptr <code>InitialTimeZoneRule</code> and
0111      * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
0112      * instances up to the size specified by trscount.  The results are referencing the
0113      * rule instance held by this time zone instance.  Therefore, after this time zone
0114      * is destructed, they are no longer available.
0115      * @param initial       Receives the initial timezone rule
0116      * @param trsrules      Receives the timezone transition rules
0117      * @param trscount      On input, specify the size of the array 'transitions' receiving
0118      *                      the timezone transition rules.  On output, actual number of
0119      *                      rules filled in the array will be set.
0120      * @param status        Receives error status code.
0121      * @stable ICU 3.8
0122      */
0123     virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
0124         const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const = 0;
0125 
0126     /**
0127      * Gets the set of time zone rules valid at the specified time.  Some known external time zone
0128      * implementations are not capable to handle historic time zone rule changes.  Also some
0129      * implementations can only handle certain type of rule definitions.
0130      * If this time zone does not use any daylight saving time within about 1 year from the specified
0131      * time, only the <code>InitialTimeZone</code> is returned.  Otherwise, the rule for standard
0132      * time and daylight saving time transitions are returned in addition to the
0133      * <code>InitialTimeZoneRule</code>.  The standard and daylight saving time transition rules are
0134      * represented by <code>AnnualTimeZoneRule</code> with <code>DateTimeRule::DOW</code> for its date
0135      * rule and <code>DateTimeRule::WALL_TIME</code> for its time rule.  Because daylight saving time
0136      * rule is changing time to time in many time zones and also mapping a transition time rule to
0137      * different type is lossy transformation, the set of rules returned by this method may be valid
0138      * for short period of time.
0139      * The time zone rule objects returned by this method is owned by the caller, so the caller is
0140      * responsible for deleting them after use.
0141      * @param date      The date used for extracting time zone rules.
0142      * @param initial   Receives the <code>InitialTimeZone</code>, always not nullptr.
0143      * @param std       Receives the <code>AnnualTimeZoneRule</code> for standard time transitions.
0144      *                  When this time time zone does not observe daylight saving times around the
0145      *                  specified date, nullptr is set.
0146      * @param dst       Receives the <code>AnnualTimeZoneRule</code> for daylight saving time
0147      *                  transitions.  When this time zone does not observer daylight saving times
0148      *                  around the specified date, nullptr is set.
0149      * @param status    Receives error status code.
0150      * @stable ICU 3.8
0151      */
0152     virtual void getSimpleRulesNear(UDate date, InitialTimeZoneRule*& initial,
0153         AnnualTimeZoneRule*& std, AnnualTimeZoneRule*& dst, UErrorCode& status) const;
0154 
0155     /**
0156      * Get time zone offsets from local wall time.
0157      * @stable ICU 69
0158      */
0159     virtual void getOffsetFromLocal(
0160         UDate date, UTimeZoneLocalOption nonExistingTimeOpt,
0161         UTimeZoneLocalOption duplicatedTimeOpt, int32_t& rawOffset,
0162         int32_t& dstOffset, UErrorCode& status) const;
0163 
0164 
0165 #ifndef U_HIDE_INTERNAL_API
0166     /**
0167      * The time type option bit flags used by getOffsetFromLocal
0168      * @internal
0169      */
0170     enum {
0171         kStandard = 0x01,
0172         kDaylight = 0x03,
0173         kFormer = 0x04, /* UCAL_TZ_LOCAL_FORMER */
0174         kLatter = 0x0C  /* UCAL_TZ_LOCAL_LATTER */
0175     };
0176 
0177     /**
0178      * Get time zone offsets from local wall time.
0179      * @internal
0180      */
0181     void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
0182         int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const;
0183 #endif  /* U_HIDE_INTERNAL_API */
0184 
0185 protected:
0186 
0187 #ifndef U_HIDE_INTERNAL_API
0188     /**
0189      * A time type option bit mask used by getOffsetFromLocal.
0190      * @internal
0191      */
0192     static constexpr int32_t kStdDstMask = kDaylight;
0193     /**
0194      * A time type option bit mask used by getOffsetFromLocal.
0195      * @internal
0196      */
0197     static constexpr int32_t kFormerLatterMask = kLatter;
0198 #endif  /* U_HIDE_INTERNAL_API */
0199 
0200     /**
0201      * Default constructor.
0202      * @stable ICU 3.8
0203      */
0204     BasicTimeZone();
0205 
0206     /**
0207      * Construct a timezone with a given ID.
0208      * @param id a system time zone ID
0209      * @stable ICU 3.8
0210      */
0211     BasicTimeZone(const UnicodeString &id);
0212 
0213     /**
0214      * Copy constructor.
0215      * @param source the object to be copied.
0216      * @stable ICU 3.8
0217      */
0218     BasicTimeZone(const BasicTimeZone& source);
0219 
0220     /**
0221      * Copy assignment.
0222      * @stable ICU 3.8
0223      */
0224     BasicTimeZone& operator=(const BasicTimeZone&) = default;
0225 
0226     /**
0227      * Gets the set of TimeZoneRule instances applicable to the specified time and after.
0228      * @param start     The start date used for extracting time zone rules
0229      * @param initial   Output parameter, receives the InitialTimeZone.
0230      *                  Always not nullptr (except in case of error)
0231      * @param transitionRules   Output parameter, a UVector of transition rules.
0232      *                  May be nullptr, if there are no transition rules.
0233      *                  The caller owns the returned vector; the UVector owns the rules.
0234      * @param status    Receives error status code
0235      */
0236     void getTimeZoneRulesAfter(UDate start, InitialTimeZoneRule*& initial, UVector*& transitionRules,
0237         UErrorCode& status) const;
0238 };
0239 
0240 U_NAMESPACE_END
0241 
0242 #endif /* #if !UCONFIG_NO_FORMATTING */
0243 
0244 #endif /* U_SHOW_CPLUSPLUS_API */
0245 
0246 #endif // BASICTZ_H
0247 
0248 //eof