dtrule.h 8.7 KB

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