dtrule.h 8.5 KB

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