1 /* 2 ******************************************************************************* 3 * Copyright (C) 2007-2010, International Business Machines Corporation and 4 * others. All Rights Reserved. 5 ******************************************************************************* 6 */ 7 8 #include <typeinfo> // 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 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 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 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 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 60 DateTimeRule::~DateTimeRule() { 61 } 62 63 DateTimeRule* 64 DateTimeRule::clone() const { 65 return new DateTimeRule(*this); 66 } 67 68 DateTimeRule& 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 83 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 96 DateTimeRule::operator!=(const DateTimeRule& that) const { 97 return !operator==(that); 98 } 99 100 DateTimeRule::DateRuleType 101 DateTimeRule::getDateRuleType(void) const { 102 return fDateRuleType; 103 } 104 105 DateTimeRule::TimeRuleType 106 DateTimeRule::getTimeRuleType(void) const { 107 return fTimeRuleType; 108 } 109 110 int32_t 111 DateTimeRule::getRuleMonth(void) const { 112 return fMonth; 113 } 114 115 int32_t 116 DateTimeRule::getRuleDayOfMonth(void) const { 117 return fDayOfMonth; 118 } 119 120 int32_t 121 DateTimeRule::getRuleDayOfWeek(void) const { 122 return fDayOfWeek; 123 } 124 125 int32_t 126 DateTimeRule::getRuleWeekInMonth(void) const { 127 return fWeekInMonth; 128 } 129 130 int32_t 131 DateTimeRule::getRuleMillisInDay(void) const { 132 return fMillisInDay; 133 } 134 135 U_NAMESPACE_END 136 137 #endif /* #if !UCONFIG_NO_FORMATTING */ 138 139 //eof 140