]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/dtrule.cpp
ICU-62141.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / dtrule.cpp
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
46f4442e
A
3/*
4*******************************************************************************
51004dcb 5* Copyright (C) 2007-2012, International Business Machines Corporation and
729e4ab9 6* others. All Rights Reserved.
46f4442e
A
7*******************************************************************************
8*/
9
51004dcb 10#include "utypeinfo.h" // for 'typeid' to work
729e4ab9 11
46f4442e
A
12#include "unicode/utypes.h"
13
14#if !UCONFIG_NO_FORMATTING
15
16#include "unicode/dtrule.h"
17
18U_NAMESPACE_BEGIN
19
20UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateTimeRule)
21
22DateTimeRule::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
30DateTimeRule::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
39DateTimeRule::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
55DateTimeRule::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
62DateTimeRule::~DateTimeRule() {
63}
64
65DateTimeRule*
66DateTimeRule::clone() const {
67 return new DateTimeRule(*this);
68}
69
70DateTimeRule&
71DateTimeRule::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
84UBool
85DateTimeRule::operator==(const DateTimeRule& that) const {
86 return ((this == &that) ||
729e4ab9 87 (typeid(*this) == typeid(that) &&
46f4442e
A
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
97UBool
98DateTimeRule::operator!=(const DateTimeRule& that) const {
99 return !operator==(that);
100}
101
102DateTimeRule::DateRuleType
103DateTimeRule::getDateRuleType(void) const {
104 return fDateRuleType;
105}
106
107DateTimeRule::TimeRuleType
108DateTimeRule::getTimeRuleType(void) const {
109 return fTimeRuleType;
110}
111
112int32_t
113DateTimeRule::getRuleMonth(void) const {
114 return fMonth;
115}
116
117int32_t
118DateTimeRule::getRuleDayOfMonth(void) const {
119 return fDayOfMonth;
120}
121
122int32_t
123DateTimeRule::getRuleDayOfWeek(void) const {
124 return fDayOfWeek;
125}
126
127int32_t
128DateTimeRule::getRuleWeekInMonth(void) const {
129 return fWeekInMonth;
130}
131
132int32_t
133DateTimeRule::getRuleMillisInDay(void) const {
134 return fMillisInDay;
135}
136
137U_NAMESPACE_END
138
139#endif /* #if !UCONFIG_NO_FORMATTING */
140
141//eof