• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-2012, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
8 */
9 
10 #include "utypeinfo.h"  // for 'typeid' to work
11 
12 #include "unicode/utypes.h"
13 
14 #if !UCONFIG_NO_FORMATTING
15 
16 #include "unicode/dtrule.h"
17 
18 U_NAMESPACE_BEGIN
19 
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateTimeRule)20 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateTimeRule)
21 
22 DateTimeRule::DateTimeRule(int32_t month,
23                            int32_t dayOfMonth,
24                            int32_t millisInDay,
25                            TimeRuleType timeType)
26 : fMonth(month), fDayOfMonth(dayOfMonth), fDayOfWeek(0), fWeekInMonth(0), fMillisInDay(millisInDay),
27   fDateRuleType(DateTimeRule::DOM), fTimeRuleType(timeType) {
28 }
29 
DateTimeRule(int32_t month,int32_t weekInMonth,int32_t dayOfWeek,int32_t millisInDay,TimeRuleType timeType)30 DateTimeRule::DateTimeRule(int32_t month,
31                            int32_t weekInMonth,
32                            int32_t dayOfWeek,
33                            int32_t millisInDay,
34                            TimeRuleType timeType)
35 : fMonth(month), fDayOfMonth(0), fDayOfWeek(dayOfWeek), fWeekInMonth(weekInMonth), fMillisInDay(millisInDay),
36   fDateRuleType(DateTimeRule::DOW), fTimeRuleType(timeType) {
37 }
38 
DateTimeRule(int32_t month,int32_t dayOfMonth,int32_t dayOfWeek,UBool after,int32_t millisInDay,TimeRuleType timeType)39 DateTimeRule::DateTimeRule(int32_t month,
40                            int32_t dayOfMonth,
41                            int32_t dayOfWeek,
42                            UBool after,
43                            int32_t millisInDay,
44                            TimeRuleType timeType)
45 : UObject(),
46   fMonth(month), fDayOfMonth(dayOfMonth), fDayOfWeek(dayOfWeek), fWeekInMonth(0), fMillisInDay(millisInDay),
47   fTimeRuleType(timeType) {
48     if (after) {
49         fDateRuleType = DateTimeRule::DOW_GEQ_DOM;
50     } else {
51         fDateRuleType = DateTimeRule::DOW_LEQ_DOM;
52     }
53 }
54 
DateTimeRule(const DateTimeRule & source)55 DateTimeRule::DateTimeRule(const DateTimeRule& source)
56 : UObject(source),
57   fMonth(source.fMonth), fDayOfMonth(source.fDayOfMonth), fDayOfWeek(source.fDayOfWeek),
58   fWeekInMonth(source.fWeekInMonth), fMillisInDay(source.fMillisInDay),
59   fDateRuleType(source.fDateRuleType), fTimeRuleType(source.fTimeRuleType) {
60 }
61 
~DateTimeRule()62 DateTimeRule::~DateTimeRule() {
63 }
64 
65 DateTimeRule*
clone() const66 DateTimeRule::clone() const {
67     return new DateTimeRule(*this);
68 }
69 
70 DateTimeRule&
operator =(const DateTimeRule & right)71 DateTimeRule::operator=(const DateTimeRule& right) {
72     if (this != &right) {
73         fMonth = right.fMonth;
74         fDayOfMonth = right.fDayOfMonth;
75         fDayOfWeek = right.fDayOfWeek;
76         fWeekInMonth = right.fWeekInMonth;
77         fMillisInDay = right.fMillisInDay;
78         fDateRuleType = right.fDateRuleType;
79         fTimeRuleType = right.fTimeRuleType;
80     }
81     return *this;
82 }
83 
84 UBool
operator ==(const DateTimeRule & that) const85 DateTimeRule::operator==(const DateTimeRule& that) const {
86     return ((this == &that) ||
87             (typeid(*this) == typeid(that) &&
88             fMonth == that.fMonth &&
89             fDayOfMonth == that.fDayOfMonth &&
90             fDayOfWeek == that.fDayOfWeek &&
91             fWeekInMonth == that.fWeekInMonth &&
92             fMillisInDay == that.fMillisInDay &&
93             fDateRuleType == that.fDateRuleType &&
94             fTimeRuleType == that.fTimeRuleType));
95 }
96 
97 UBool
operator !=(const DateTimeRule & that) const98 DateTimeRule::operator!=(const DateTimeRule& that) const {
99     return !operator==(that);
100 }
101 
102 DateTimeRule::DateRuleType
getDateRuleType(void) const103 DateTimeRule::getDateRuleType(void) const {
104     return fDateRuleType;
105 }
106 
107 DateTimeRule::TimeRuleType
getTimeRuleType(void) const108 DateTimeRule::getTimeRuleType(void) const {
109     return fTimeRuleType;
110 }
111 
112 int32_t
getRuleMonth(void) const113 DateTimeRule::getRuleMonth(void) const {
114     return fMonth;
115 }
116 
117 int32_t
getRuleDayOfMonth(void) const118 DateTimeRule::getRuleDayOfMonth(void) const {
119     return fDayOfMonth;
120 }
121 
122 int32_t
getRuleDayOfWeek(void) const123 DateTimeRule::getRuleDayOfWeek(void) const {
124     return fDayOfWeek;
125 }
126 
127 int32_t
getRuleWeekInMonth(void) const128 DateTimeRule::getRuleWeekInMonth(void) const {
129     return fWeekInMonth;
130 }
131 
132 int32_t
getRuleMillisInDay(void) const133 DateTimeRule::getRuleMillisInDay(void) const {
134     return fMillisInDay;
135 }
136 
137 U_NAMESPACE_END
138 
139 #endif /* #if !UCONFIG_NO_FORMATTING */
140 
141 //eof
142