1 /*
2 *******************************************************************************
3 * Copyright (C) 2007-2012, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
6 */
7 
8 #include "utypeinfo.h"  // for 'typeid' to work
9 
10 #include "unicode/utypes.h"
11 
12 #if !UCONFIG_NO_FORMATTING
13 
14 #include "unicode/dtrule.h"
15 
16 U_NAMESPACE_BEGIN
17 
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateTimeRule)18 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateTimeRule)
19 
20 DateTimeRule::DateTimeRule(int32_t month,
21                            int32_t dayOfMonth,
22                            int32_t millisInDay,
23                            TimeRuleType timeType)
24 : fMonth(month), fDayOfMonth(dayOfMonth), fDayOfWeek(0), fWeekInMonth(0), fMillisInDay(millisInDay),
25   fDateRuleType(DateTimeRule::DOM), fTimeRuleType(timeType) {
26 }
27 
DateTimeRule(int32_t month,int32_t weekInMonth,int32_t dayOfWeek,int32_t millisInDay,TimeRuleType timeType)28 DateTimeRule::DateTimeRule(int32_t month,
29                            int32_t weekInMonth,
30                            int32_t dayOfWeek,
31                            int32_t millisInDay,
32                            TimeRuleType timeType)
33 : fMonth(month), fDayOfMonth(0), fDayOfWeek(dayOfWeek), fWeekInMonth(weekInMonth), fMillisInDay(millisInDay),
34   fDateRuleType(DateTimeRule::DOW), fTimeRuleType(timeType) {
35 }
36 
DateTimeRule(int32_t month,int32_t dayOfMonth,int32_t dayOfWeek,UBool after,int32_t millisInDay,TimeRuleType timeType)37 DateTimeRule::DateTimeRule(int32_t month,
38                            int32_t dayOfMonth,
39                            int32_t dayOfWeek,
40                            UBool after,
41                            int32_t millisInDay,
42                            TimeRuleType timeType)
43 : UObject(),
44   fMonth(month), fDayOfMonth(dayOfMonth), fDayOfWeek(dayOfWeek), fWeekInMonth(0), fMillisInDay(millisInDay),
45   fTimeRuleType(timeType) {
46     if (after) {
47         fDateRuleType = DateTimeRule::DOW_GEQ_DOM;
48     } else {
49         fDateRuleType = DateTimeRule::DOW_LEQ_DOM;
50     }
51 }
52 
DateTimeRule(const DateTimeRule & source)53 DateTimeRule::DateTimeRule(const DateTimeRule& source)
54 : UObject(source),
55   fMonth(source.fMonth), fDayOfMonth(source.fDayOfMonth), fDayOfWeek(source.fDayOfWeek),
56   fWeekInMonth(source.fWeekInMonth), fMillisInDay(source.fMillisInDay),
57   fDateRuleType(source.fDateRuleType), fTimeRuleType(source.fTimeRuleType) {
58 }
59 
~DateTimeRule()60 DateTimeRule::~DateTimeRule() {
61 }
62 
63 DateTimeRule*
clone() const64 DateTimeRule::clone() const {
65     return new DateTimeRule(*this);
66 }
67 
68 DateTimeRule&
operator =(const DateTimeRule & right)69 DateTimeRule::operator=(const DateTimeRule& right) {
70     if (this != &right) {
71         fMonth = right.fMonth;
72         fDayOfMonth = right.fDayOfMonth;
73         fDayOfWeek = right.fDayOfWeek;
74         fWeekInMonth = right.fWeekInMonth;
75         fMillisInDay = right.fMillisInDay;
76         fDateRuleType = right.fDateRuleType;
77         fTimeRuleType = right.fTimeRuleType;
78     }
79     return *this;
80 }
81 
82 UBool
operator ==(const DateTimeRule & that) const83 DateTimeRule::operator==(const DateTimeRule& that) const {
84     return ((this == &that) ||
85             (typeid(*this) == typeid(that) &&
86             fMonth == that.fMonth &&
87             fDayOfMonth == that.fDayOfMonth &&
88             fDayOfWeek == that.fDayOfWeek &&
89             fWeekInMonth == that.fWeekInMonth &&
90             fMillisInDay == that.fMillisInDay &&
91             fDateRuleType == that.fDateRuleType &&
92             fTimeRuleType == that.fTimeRuleType));
93 }
94 
95 UBool
operator !=(const DateTimeRule & that) const96 DateTimeRule::operator!=(const DateTimeRule& that) const {
97     return !operator==(that);
98 }
99 
100 DateTimeRule::DateRuleType
getDateRuleType(void) const101 DateTimeRule::getDateRuleType(void) const {
102     return fDateRuleType;
103 }
104 
105 DateTimeRule::TimeRuleType
getTimeRuleType(void) const106 DateTimeRule::getTimeRuleType(void) const {
107     return fTimeRuleType;
108 }
109 
110 int32_t
getRuleMonth(void) const111 DateTimeRule::getRuleMonth(void) const {
112     return fMonth;
113 }
114 
115 int32_t
getRuleDayOfMonth(void) const116 DateTimeRule::getRuleDayOfMonth(void) const {
117     return fDayOfMonth;
118 }
119 
120 int32_t
getRuleDayOfWeek(void) const121 DateTimeRule::getRuleDayOfWeek(void) const {
122     return fDayOfWeek;
123 }
124 
125 int32_t
getRuleWeekInMonth(void) const126 DateTimeRule::getRuleWeekInMonth(void) const {
127     return fWeekInMonth;
128 }
129 
130 int32_t
getRuleMillisInDay(void) const131 DateTimeRule::getRuleMillisInDay(void) const {
132     return fMillisInDay;
133 }
134 
135 U_NAMESPACE_END
136 
137 #endif /* #if !UCONFIG_NO_FORMATTING */
138 
139 //eof
140