dtrule.h 8.6 KB

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