michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 2007-2008, International Business Machines Corporation and * michael@0: * others. All Rights Reserved. * michael@0: ******************************************************************************* michael@0: */ michael@0: #ifndef DTRULE_H michael@0: #define DTRULE_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: Rule for specifying date and time in an year michael@0: */ michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/uobject.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: /** michael@0: * DateTimeRule is a class representing a time in a year by michael@0: * a rule specified by month, day of month, day of week and michael@0: * time in the day. michael@0: * michael@0: * @stable ICU 3.8 michael@0: */ michael@0: class U_I18N_API DateTimeRule : public UObject { michael@0: public: michael@0: michael@0: /** michael@0: * Date rule type constants. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: enum DateRuleType { michael@0: DOM = 0, /**< The exact day of month, michael@0: for example, March 11. */ michael@0: DOW, /**< The Nth occurence of the day of week, michael@0: for example, 2nd Sunday in March. */ michael@0: DOW_GEQ_DOM, /**< The first occurence of the day of week on or after the day of monnth, michael@0: for example, first Sunday on or after March 8. */ michael@0: DOW_LEQ_DOM /**< The last occurence of the day of week on or before the day of month, michael@0: for example, first Sunday on or before March 14. */ michael@0: }; michael@0: michael@0: /** michael@0: * Time rule type constants. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: enum TimeRuleType { michael@0: WALL_TIME = 0, /**< The local wall clock time */ michael@0: STANDARD_TIME, /**< The local standard time */ michael@0: UTC_TIME /**< The UTC time */ michael@0: }; michael@0: michael@0: /** michael@0: * Constructs a DateTimeRule by the day of month and michael@0: * the time rule. The date rule type for an instance created by michael@0: * this constructor is DOM. michael@0: * michael@0: * @param month The rule month, for example, Calendar::JANUARY michael@0: * @param dayOfMonth The day of month, 1-based. michael@0: * @param millisInDay The milliseconds in the rule date. michael@0: * @param timeType The time type, WALL_TIME or STANDARD_TIME michael@0: * or UTC_TIME. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: DateTimeRule(int32_t month, int32_t dayOfMonth, michael@0: int32_t millisInDay, TimeRuleType timeType); michael@0: michael@0: /** michael@0: * Constructs a DateTimeRule by the day of week and its oridinal michael@0: * number and the time rule. The date rule type for an instance created michael@0: * by this constructor is DOW. michael@0: * michael@0: * @param month The rule month, for example, Calendar::JANUARY. michael@0: * @param weekInMonth The ordinal number of the day of week. Negative number michael@0: * may be used for specifying a rule date counted from the michael@0: * end of the rule month. michael@0: * @param dayOfWeek The day of week, for example, Calendar::SUNDAY. michael@0: * @param millisInDay The milliseconds in the rule date. michael@0: * @param timeType The time type, WALL_TIME or STANDARD_TIME michael@0: * or UTC_TIME. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: DateTimeRule(int32_t month, int32_t weekInMonth, int32_t dayOfWeek, michael@0: int32_t millisInDay, TimeRuleType timeType); michael@0: michael@0: /** michael@0: * Constructs a DateTimeRule by the first/last day of week michael@0: * on or after/before the day of month and the time rule. The date rule michael@0: * type for an instance created by this constructor is either michael@0: * DOM_GEQ_DOM or DOM_LEQ_DOM. michael@0: * michael@0: * @param month The rule month, for example, Calendar::JANUARY michael@0: * @param dayOfMonth The day of month, 1-based. michael@0: * @param dayOfWeek The day of week, for example, Calendar::SUNDAY. michael@0: * @param after true if the rule date is on or after the day of month. michael@0: * @param millisInDay The milliseconds in the rule date. michael@0: * @param timeType The time type, WALL_TIME or STANDARD_TIME michael@0: * or UTC_TIME. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: DateTimeRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, UBool after, michael@0: int32_t millisInDay, TimeRuleType timeType); michael@0: michael@0: /** michael@0: * Copy constructor. michael@0: * @param source The DateTimeRule object to be copied. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: DateTimeRule(const DateTimeRule& source); michael@0: michael@0: /** michael@0: * Destructor. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: ~DateTimeRule(); michael@0: michael@0: /** michael@0: * Clone this DateTimeRule object polymorphically. The caller owns the result and michael@0: * should delete it when done. michael@0: * @return A copy of the object. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: DateTimeRule* clone(void) const; michael@0: michael@0: /** michael@0: * Assignment operator. michael@0: * @param right The object to be copied. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: DateTimeRule& operator=(const DateTimeRule& right); michael@0: michael@0: /** michael@0: * Return true if the given DateTimeRule objects are semantically equal. Objects michael@0: * of different subclasses are considered unequal. michael@0: * @param that The object to be compared with. michael@0: * @return true if the given DateTimeRule objects are semantically equal. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: UBool operator==(const DateTimeRule& that) const; michael@0: michael@0: /** michael@0: * Return true if the given DateTimeRule objects are semantically unequal. Objects michael@0: * of different subclasses are considered unequal. michael@0: * @param that The object to be compared with. michael@0: * @return true if the given DateTimeRule objects are semantically unequal. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: UBool operator!=(const DateTimeRule& that) const; michael@0: michael@0: /** michael@0: * Gets the date rule type, such as DOM michael@0: * @return The date rule type. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: DateRuleType getDateRuleType(void) const; michael@0: michael@0: /** michael@0: * Gets the time rule type michael@0: * @return The time rule type, either WALL_TIME or STANDARD_TIME michael@0: * or UTC_TIME. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: TimeRuleType getTimeRuleType(void) const; michael@0: michael@0: /** michael@0: * Gets the rule month. michael@0: * @return The rule month. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: int32_t getRuleMonth(void) const; michael@0: michael@0: /** michael@0: * Gets the rule day of month. When the date rule type michael@0: * is DOW, the value is always 0. michael@0: * @return The rule day of month michael@0: * @stable ICU 3.8 michael@0: */ michael@0: int32_t getRuleDayOfMonth(void) const; michael@0: michael@0: /** michael@0: * Gets the rule day of week. When the date rule type michael@0: * is DOM, the value is always 0. michael@0: * @return The rule day of week. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: int32_t getRuleDayOfWeek(void) const; michael@0: michael@0: /** michael@0: * Gets the ordinal number of the occurence of the day of week michael@0: * in the month. When the date rule type is not DOW, michael@0: * the value is always 0. michael@0: * @return The rule day of week ordinal number in the month. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: int32_t getRuleWeekInMonth(void) const; michael@0: michael@0: /** michael@0: * Gets the rule time in the rule day. michael@0: * @return The time in the rule day in milliseconds. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: int32_t getRuleMillisInDay(void) const; michael@0: michael@0: private: michael@0: int32_t fMonth; michael@0: int32_t fDayOfMonth; michael@0: int32_t fDayOfWeek; michael@0: int32_t fWeekInMonth; michael@0: int32_t fMillisInDay; michael@0: DateRuleType fDateRuleType; michael@0: TimeRuleType fTimeRuleType; michael@0: michael@0: public: michael@0: /** michael@0: * Return the class ID for this class. This is useful only for comparing to michael@0: * a return value from getDynamicClassID(). For example: michael@0: *
michael@0:      * .   Base* polymorphic_pointer = createPolymorphicObject();
michael@0:      * .   if (polymorphic_pointer->getDynamicClassID() ==
michael@0:      * .       erived::getStaticClassID()) ...
michael@0:      * 
michael@0: * @return The class ID for all objects of this class. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(void); michael@0: michael@0: /** michael@0: * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This michael@0: * method is to implement a simple version of RTTI, since not all C++ michael@0: * compilers support genuine RTTI. Polymorphic operator==() and clone() michael@0: * methods call this method. michael@0: * michael@0: * @return The class ID for this object. All objects of a michael@0: * given class have the same class ID. Objects of michael@0: * other classes have different class IDs. michael@0: * @stable ICU 3.8 michael@0: */ michael@0: virtual UClassID getDynamicClassID(void) const; michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif // DTRULE_H michael@0: //eof