1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker /* 4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************* 5*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2007-2008, International Business Machines Corporation and * 6*0e209d39SAndroid Build Coastguard Worker * others. All Rights Reserved. * 7*0e209d39SAndroid Build Coastguard Worker ******************************************************************************* 8*0e209d39SAndroid Build Coastguard Worker */ 9*0e209d39SAndroid Build Coastguard Worker #ifndef DTRULE_H 10*0e209d39SAndroid Build Coastguard Worker #define DTRULE_H 11*0e209d39SAndroid Build Coastguard Worker 12*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 13*0e209d39SAndroid Build Coastguard Worker 14*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API 15*0e209d39SAndroid Build Coastguard Worker 16*0e209d39SAndroid Build Coastguard Worker /** 17*0e209d39SAndroid Build Coastguard Worker * \file 18*0e209d39SAndroid Build Coastguard Worker * \brief C++ API: Rule for specifying date and time in an year 19*0e209d39SAndroid Build Coastguard Worker */ 20*0e209d39SAndroid Build Coastguard Worker 21*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING 22*0e209d39SAndroid Build Coastguard Worker 23*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h" 24*0e209d39SAndroid Build Coastguard Worker 25*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 26*0e209d39SAndroid Build Coastguard Worker /** 27*0e209d39SAndroid Build Coastguard Worker * <code>DateTimeRule</code> is a class representing a time in a year by 28*0e209d39SAndroid Build Coastguard Worker * a rule specified by month, day of month, day of week and 29*0e209d39SAndroid Build Coastguard Worker * time in the day. 30*0e209d39SAndroid Build Coastguard Worker * 31*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 32*0e209d39SAndroid Build Coastguard Worker */ 33*0e209d39SAndroid Build Coastguard Worker class U_I18N_API DateTimeRule : public UObject { 34*0e209d39SAndroid Build Coastguard Worker public: 35*0e209d39SAndroid Build Coastguard Worker 36*0e209d39SAndroid Build Coastguard Worker /** 37*0e209d39SAndroid Build Coastguard Worker * Date rule type constants. 38*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 39*0e209d39SAndroid Build Coastguard Worker */ 40*0e209d39SAndroid Build Coastguard Worker enum DateRuleType { 41*0e209d39SAndroid Build Coastguard Worker DOM = 0, /**< The exact day of month, 42*0e209d39SAndroid Build Coastguard Worker for example, March 11. */ 43*0e209d39SAndroid Build Coastguard Worker DOW, /**< The Nth occurrence of the day of week, 44*0e209d39SAndroid Build Coastguard Worker for example, 2nd Sunday in March. */ 45*0e209d39SAndroid Build Coastguard Worker DOW_GEQ_DOM, /**< The first occurrence of the day of week on or after the day of monnth, 46*0e209d39SAndroid Build Coastguard Worker for example, first Sunday on or after March 8. */ 47*0e209d39SAndroid Build Coastguard Worker DOW_LEQ_DOM /**< The last occurrence of the day of week on or before the day of month, 48*0e209d39SAndroid Build Coastguard Worker for example, first Sunday on or before March 14. */ 49*0e209d39SAndroid Build Coastguard Worker }; 50*0e209d39SAndroid Build Coastguard Worker 51*0e209d39SAndroid Build Coastguard Worker /** 52*0e209d39SAndroid Build Coastguard Worker * Time rule type constants. 53*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 54*0e209d39SAndroid Build Coastguard Worker */ 55*0e209d39SAndroid Build Coastguard Worker enum TimeRuleType { 56*0e209d39SAndroid Build Coastguard Worker WALL_TIME = 0, /**< The local wall clock time */ 57*0e209d39SAndroid Build Coastguard Worker STANDARD_TIME, /**< The local standard time */ 58*0e209d39SAndroid Build Coastguard Worker UTC_TIME /**< The UTC time */ 59*0e209d39SAndroid Build Coastguard Worker }; 60*0e209d39SAndroid Build Coastguard Worker 61*0e209d39SAndroid Build Coastguard Worker /** 62*0e209d39SAndroid Build Coastguard Worker * Constructs a <code>DateTimeRule</code> by the day of month and 63*0e209d39SAndroid Build Coastguard Worker * the time rule. The date rule type for an instance created by 64*0e209d39SAndroid Build Coastguard Worker * this constructor is <code>DOM</code>. 65*0e209d39SAndroid Build Coastguard Worker * 66*0e209d39SAndroid Build Coastguard Worker * @param month The rule month, for example, <code>Calendar::JANUARY</code> 67*0e209d39SAndroid Build Coastguard Worker * @param dayOfMonth The day of month, 1-based. 68*0e209d39SAndroid Build Coastguard Worker * @param millisInDay The milliseconds in the rule date. 69*0e209d39SAndroid Build Coastguard Worker * @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code> 70*0e209d39SAndroid Build Coastguard Worker * or <code>UTC_TIME</code>. 71*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 72*0e209d39SAndroid Build Coastguard Worker */ 73*0e209d39SAndroid Build Coastguard Worker DateTimeRule(int32_t month, int32_t dayOfMonth, 74*0e209d39SAndroid Build Coastguard Worker int32_t millisInDay, TimeRuleType timeType); 75*0e209d39SAndroid Build Coastguard Worker 76*0e209d39SAndroid Build Coastguard Worker /** 77*0e209d39SAndroid Build Coastguard Worker * Constructs a <code>DateTimeRule</code> by the day of week and its ordinal 78*0e209d39SAndroid Build Coastguard Worker * number and the time rule. The date rule type for an instance created 79*0e209d39SAndroid Build Coastguard Worker * by this constructor is <code>DOW</code>. 80*0e209d39SAndroid Build Coastguard Worker * 81*0e209d39SAndroid Build Coastguard Worker * @param month The rule month, for example, <code>Calendar::JANUARY</code>. 82*0e209d39SAndroid Build Coastguard Worker * @param weekInMonth The ordinal number of the day of week. Negative number 83*0e209d39SAndroid Build Coastguard Worker * may be used for specifying a rule date counted from the 84*0e209d39SAndroid Build Coastguard Worker * end of the rule month. 85*0e209d39SAndroid Build Coastguard Worker * @param dayOfWeek The day of week, for example, <code>Calendar::SUNDAY</code>. 86*0e209d39SAndroid Build Coastguard Worker * @param millisInDay The milliseconds in the rule date. 87*0e209d39SAndroid Build Coastguard Worker * @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code> 88*0e209d39SAndroid Build Coastguard Worker * or <code>UTC_TIME</code>. 89*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 90*0e209d39SAndroid Build Coastguard Worker */ 91*0e209d39SAndroid Build Coastguard Worker DateTimeRule(int32_t month, int32_t weekInMonth, int32_t dayOfWeek, 92*0e209d39SAndroid Build Coastguard Worker int32_t millisInDay, TimeRuleType timeType); 93*0e209d39SAndroid Build Coastguard Worker 94*0e209d39SAndroid Build Coastguard Worker /** 95*0e209d39SAndroid Build Coastguard Worker * Constructs a <code>DateTimeRule</code> by the first/last day of week 96*0e209d39SAndroid Build Coastguard Worker * on or after/before the day of month and the time rule. The date rule 97*0e209d39SAndroid Build Coastguard Worker * type for an instance created by this constructor is either 98*0e209d39SAndroid Build Coastguard Worker * <code>DOM_GEQ_DOM</code> or <code>DOM_LEQ_DOM</code>. 99*0e209d39SAndroid Build Coastguard Worker * 100*0e209d39SAndroid Build Coastguard Worker * @param month The rule month, for example, <code>Calendar::JANUARY</code> 101*0e209d39SAndroid Build Coastguard Worker * @param dayOfMonth The day of month, 1-based. 102*0e209d39SAndroid Build Coastguard Worker * @param dayOfWeek The day of week, for example, <code>Calendar::SUNDAY</code>. 103*0e209d39SAndroid Build Coastguard Worker * @param after true if the rule date is on or after the day of month. 104*0e209d39SAndroid Build Coastguard Worker * @param millisInDay The milliseconds in the rule date. 105*0e209d39SAndroid Build Coastguard Worker * @param timeType The time type, <code>WALL_TIME</code> or <code>STANDARD_TIME</code> 106*0e209d39SAndroid Build Coastguard Worker * or <code>UTC_TIME</code>. 107*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 108*0e209d39SAndroid Build Coastguard Worker */ 109*0e209d39SAndroid Build Coastguard Worker DateTimeRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, UBool after, 110*0e209d39SAndroid Build Coastguard Worker int32_t millisInDay, TimeRuleType timeType); 111*0e209d39SAndroid Build Coastguard Worker 112*0e209d39SAndroid Build Coastguard Worker /** 113*0e209d39SAndroid Build Coastguard Worker * Copy constructor. 114*0e209d39SAndroid Build Coastguard Worker * @param source The DateTimeRule object to be copied. 115*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 116*0e209d39SAndroid Build Coastguard Worker */ 117*0e209d39SAndroid Build Coastguard Worker DateTimeRule(const DateTimeRule& source); 118*0e209d39SAndroid Build Coastguard Worker 119*0e209d39SAndroid Build Coastguard Worker /** 120*0e209d39SAndroid Build Coastguard Worker * Destructor. 121*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 122*0e209d39SAndroid Build Coastguard Worker */ 123*0e209d39SAndroid Build Coastguard Worker ~DateTimeRule(); 124*0e209d39SAndroid Build Coastguard Worker 125*0e209d39SAndroid Build Coastguard Worker /** 126*0e209d39SAndroid Build Coastguard Worker * Clone this DateTimeRule object polymorphically. The caller owns the result and 127*0e209d39SAndroid Build Coastguard Worker * should delete it when done. 128*0e209d39SAndroid Build Coastguard Worker * @return A copy of the object. 129*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 130*0e209d39SAndroid Build Coastguard Worker */ 131*0e209d39SAndroid Build Coastguard Worker DateTimeRule* clone() const; 132*0e209d39SAndroid Build Coastguard Worker 133*0e209d39SAndroid Build Coastguard Worker /** 134*0e209d39SAndroid Build Coastguard Worker * Assignment operator. 135*0e209d39SAndroid Build Coastguard Worker * @param right The object to be copied. 136*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 137*0e209d39SAndroid Build Coastguard Worker */ 138*0e209d39SAndroid Build Coastguard Worker DateTimeRule& operator=(const DateTimeRule& right); 139*0e209d39SAndroid Build Coastguard Worker 140*0e209d39SAndroid Build Coastguard Worker /** 141*0e209d39SAndroid Build Coastguard Worker * Return true if the given DateTimeRule objects are semantically equal. Objects 142*0e209d39SAndroid Build Coastguard Worker * of different subclasses are considered unequal. 143*0e209d39SAndroid Build Coastguard Worker * @param that The object to be compared with. 144*0e209d39SAndroid Build Coastguard Worker * @return true if the given DateTimeRule objects are semantically equal. 145*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 146*0e209d39SAndroid Build Coastguard Worker */ 147*0e209d39SAndroid Build Coastguard Worker bool operator==(const DateTimeRule& that) const; 148*0e209d39SAndroid Build Coastguard Worker 149*0e209d39SAndroid Build Coastguard Worker /** 150*0e209d39SAndroid Build Coastguard Worker * Return true if the given DateTimeRule objects are semantically unequal. Objects 151*0e209d39SAndroid Build Coastguard Worker * of different subclasses are considered unequal. 152*0e209d39SAndroid Build Coastguard Worker * @param that The object to be compared with. 153*0e209d39SAndroid Build Coastguard Worker * @return true if the given DateTimeRule objects are semantically unequal. 154*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 155*0e209d39SAndroid Build Coastguard Worker */ 156*0e209d39SAndroid Build Coastguard Worker bool operator!=(const DateTimeRule& that) const; 157*0e209d39SAndroid Build Coastguard Worker 158*0e209d39SAndroid Build Coastguard Worker /** 159*0e209d39SAndroid Build Coastguard Worker * Gets the date rule type, such as <code>DOM</code> 160*0e209d39SAndroid Build Coastguard Worker * @return The date rule type. 161*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 162*0e209d39SAndroid Build Coastguard Worker */ 163*0e209d39SAndroid Build Coastguard Worker DateRuleType getDateRuleType() const; 164*0e209d39SAndroid Build Coastguard Worker 165*0e209d39SAndroid Build Coastguard Worker /** 166*0e209d39SAndroid Build Coastguard Worker * Gets the time rule type 167*0e209d39SAndroid Build Coastguard Worker * @return The time rule type, either <code>WALL_TIME</code> or <code>STANDARD_TIME</code> 168*0e209d39SAndroid Build Coastguard Worker * or <code>UTC_TIME</code>. 169*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 170*0e209d39SAndroid Build Coastguard Worker */ 171*0e209d39SAndroid Build Coastguard Worker TimeRuleType getTimeRuleType() const; 172*0e209d39SAndroid Build Coastguard Worker 173*0e209d39SAndroid Build Coastguard Worker /** 174*0e209d39SAndroid Build Coastguard Worker * Gets the rule month. 175*0e209d39SAndroid Build Coastguard Worker * @return The rule month. 176*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 177*0e209d39SAndroid Build Coastguard Worker */ 178*0e209d39SAndroid Build Coastguard Worker int32_t getRuleMonth() const; 179*0e209d39SAndroid Build Coastguard Worker 180*0e209d39SAndroid Build Coastguard Worker /** 181*0e209d39SAndroid Build Coastguard Worker * Gets the rule day of month. When the date rule type 182*0e209d39SAndroid Build Coastguard Worker * is <code>DOW</code>, the value is always 0. 183*0e209d39SAndroid Build Coastguard Worker * @return The rule day of month 184*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 185*0e209d39SAndroid Build Coastguard Worker */ 186*0e209d39SAndroid Build Coastguard Worker int32_t getRuleDayOfMonth() const; 187*0e209d39SAndroid Build Coastguard Worker 188*0e209d39SAndroid Build Coastguard Worker /** 189*0e209d39SAndroid Build Coastguard Worker * Gets the rule day of week. When the date rule type 190*0e209d39SAndroid Build Coastguard Worker * is <code>DOM</code>, the value is always 0. 191*0e209d39SAndroid Build Coastguard Worker * @return The rule day of week. 192*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 193*0e209d39SAndroid Build Coastguard Worker */ 194*0e209d39SAndroid Build Coastguard Worker int32_t getRuleDayOfWeek() const; 195*0e209d39SAndroid Build Coastguard Worker 196*0e209d39SAndroid Build Coastguard Worker /** 197*0e209d39SAndroid Build Coastguard Worker * Gets the ordinal number of the occurrence of the day of week 198*0e209d39SAndroid Build Coastguard Worker * in the month. When the date rule type is not <code>DOW</code>, 199*0e209d39SAndroid Build Coastguard Worker * the value is always 0. 200*0e209d39SAndroid Build Coastguard Worker * @return The rule day of week ordinal number in the month. 201*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 202*0e209d39SAndroid Build Coastguard Worker */ 203*0e209d39SAndroid Build Coastguard Worker int32_t getRuleWeekInMonth() const; 204*0e209d39SAndroid Build Coastguard Worker 205*0e209d39SAndroid Build Coastguard Worker /** 206*0e209d39SAndroid Build Coastguard Worker * Gets the rule time in the rule day. 207*0e209d39SAndroid Build Coastguard Worker * @return The time in the rule day in milliseconds. 208*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 209*0e209d39SAndroid Build Coastguard Worker */ 210*0e209d39SAndroid Build Coastguard Worker int32_t getRuleMillisInDay() const; 211*0e209d39SAndroid Build Coastguard Worker 212*0e209d39SAndroid Build Coastguard Worker private: 213*0e209d39SAndroid Build Coastguard Worker int32_t fMonth; 214*0e209d39SAndroid Build Coastguard Worker int32_t fDayOfMonth; 215*0e209d39SAndroid Build Coastguard Worker int32_t fDayOfWeek; 216*0e209d39SAndroid Build Coastguard Worker int32_t fWeekInMonth; 217*0e209d39SAndroid Build Coastguard Worker int32_t fMillisInDay; 218*0e209d39SAndroid Build Coastguard Worker DateRuleType fDateRuleType; 219*0e209d39SAndroid Build Coastguard Worker TimeRuleType fTimeRuleType; 220*0e209d39SAndroid Build Coastguard Worker 221*0e209d39SAndroid Build Coastguard Worker public: 222*0e209d39SAndroid Build Coastguard Worker /** 223*0e209d39SAndroid Build Coastguard Worker * Return the class ID for this class. This is useful only for comparing to 224*0e209d39SAndroid Build Coastguard Worker * a return value from getDynamicClassID(). For example: 225*0e209d39SAndroid Build Coastguard Worker * <pre> 226*0e209d39SAndroid Build Coastguard Worker * . Base* polymorphic_pointer = createPolymorphicObject(); 227*0e209d39SAndroid Build Coastguard Worker * . if (polymorphic_pointer->getDynamicClassID() == 228*0e209d39SAndroid Build Coastguard Worker * . erived::getStaticClassID()) ... 229*0e209d39SAndroid Build Coastguard Worker * </pre> 230*0e209d39SAndroid Build Coastguard Worker * @return The class ID for all objects of this class. 231*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 232*0e209d39SAndroid Build Coastguard Worker */ 233*0e209d39SAndroid Build Coastguard Worker static UClassID U_EXPORT2 getStaticClassID(); 234*0e209d39SAndroid Build Coastguard Worker 235*0e209d39SAndroid Build Coastguard Worker /** 236*0e209d39SAndroid Build Coastguard Worker * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This 237*0e209d39SAndroid Build Coastguard Worker * method is to implement a simple version of RTTI, since not all C++ 238*0e209d39SAndroid Build Coastguard Worker * compilers support genuine RTTI. Polymorphic operator==() and clone() 239*0e209d39SAndroid Build Coastguard Worker * methods call this method. 240*0e209d39SAndroid Build Coastguard Worker * 241*0e209d39SAndroid Build Coastguard Worker * @return The class ID for this object. All objects of a 242*0e209d39SAndroid Build Coastguard Worker * given class have the same class ID. Objects of 243*0e209d39SAndroid Build Coastguard Worker * other classes have different class IDs. 244*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.8 245*0e209d39SAndroid Build Coastguard Worker */ 246*0e209d39SAndroid Build Coastguard Worker virtual UClassID getDynamicClassID() const override; 247*0e209d39SAndroid Build Coastguard Worker }; 248*0e209d39SAndroid Build Coastguard Worker 249*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 250*0e209d39SAndroid Build Coastguard Worker 251*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_FORMATTING */ 252*0e209d39SAndroid Build Coastguard Worker 253*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */ 254*0e209d39SAndroid Build Coastguard Worker 255*0e209d39SAndroid Build Coastguard Worker #endif // DTRULE_H 256*0e209d39SAndroid Build Coastguard Worker //eof 257