summaryrefslogtreecommitdiffstats
path: root/intl/icu/source/i18n/dtrule.cpp
blob: 7322cbfdad48f0acf8a0ff8038e7de74fa5be61a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 2007-2012, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/

#include "utypeinfo.h"  // for 'typeid' to work

#include "unicode/utypes.h"

#if !UCONFIG_NO_FORMATTING

#include "unicode/dtrule.h"

U_NAMESPACE_BEGIN

UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateTimeRule)

DateTimeRule::DateTimeRule(int32_t month,
                           int32_t dayOfMonth,
                           int32_t millisInDay,
                           TimeRuleType timeType)
: fMonth(month), fDayOfMonth(dayOfMonth), fDayOfWeek(0), fWeekInMonth(0), fMillisInDay(millisInDay),
  fDateRuleType(DateTimeRule::DOM), fTimeRuleType(timeType) {
}

DateTimeRule::DateTimeRule(int32_t month,
                           int32_t weekInMonth,
                           int32_t dayOfWeek,
                           int32_t millisInDay,
                           TimeRuleType timeType)
: fMonth(month), fDayOfMonth(0), fDayOfWeek(dayOfWeek), fWeekInMonth(weekInMonth), fMillisInDay(millisInDay),
  fDateRuleType(DateTimeRule::DOW), fTimeRuleType(timeType) {
}

DateTimeRule::DateTimeRule(int32_t month,
                           int32_t dayOfMonth,
                           int32_t dayOfWeek,
                           UBool after,
                           int32_t millisInDay,
                           TimeRuleType timeType)
: UObject(),
  fMonth(month), fDayOfMonth(dayOfMonth), fDayOfWeek(dayOfWeek), fWeekInMonth(0), fMillisInDay(millisInDay),
  fTimeRuleType(timeType) {
    if (after) {
        fDateRuleType = DateTimeRule::DOW_GEQ_DOM;
    } else {
        fDateRuleType = DateTimeRule::DOW_LEQ_DOM;
    }
}

DateTimeRule::DateTimeRule(const DateTimeRule& source)
: UObject(source),
  fMonth(source.fMonth), fDayOfMonth(source.fDayOfMonth), fDayOfWeek(source.fDayOfWeek),
  fWeekInMonth(source.fWeekInMonth), fMillisInDay(source.fMillisInDay),
  fDateRuleType(source.fDateRuleType), fTimeRuleType(source.fTimeRuleType) {
}

DateTimeRule::~DateTimeRule() {
}

DateTimeRule*
DateTimeRule::clone() const {
    return new DateTimeRule(*this);
}

DateTimeRule&
DateTimeRule::operator=(const DateTimeRule& right) {
    if (this != &right) {
        fMonth = right.fMonth;
        fDayOfMonth = right.fDayOfMonth;
        fDayOfWeek = right.fDayOfWeek;
        fWeekInMonth = right.fWeekInMonth;
        fMillisInDay = right.fMillisInDay;
        fDateRuleType = right.fDateRuleType;
        fTimeRuleType = right.fTimeRuleType;
    }
    return *this;
}

bool
DateTimeRule::operator==(const DateTimeRule& that) const {
    return ((this == &that) ||
            (typeid(*this) == typeid(that) &&
            fMonth == that.fMonth &&
            fDayOfMonth == that.fDayOfMonth &&
            fDayOfWeek == that.fDayOfWeek &&
            fWeekInMonth == that.fWeekInMonth &&
            fMillisInDay == that.fMillisInDay &&
            fDateRuleType == that.fDateRuleType &&
            fTimeRuleType == that.fTimeRuleType));
}

bool
DateTimeRule::operator!=(const DateTimeRule& that) const {
    return !operator==(that);
}

DateTimeRule::DateRuleType
DateTimeRule::getDateRuleType() const {
    return fDateRuleType;
}

DateTimeRule::TimeRuleType
DateTimeRule::getTimeRuleType() const {
    return fTimeRuleType;
}

int32_t
DateTimeRule::getRuleMonth() const {
    return fMonth;
}

int32_t
DateTimeRule::getRuleDayOfMonth() const {
    return fDayOfMonth;
}

int32_t
DateTimeRule::getRuleDayOfWeek() const {
    return fDayOfWeek;
}

int32_t
DateTimeRule::getRuleWeekInMonth() const {
    return fWeekInMonth;
}

int32_t
DateTimeRule::getRuleMillisInDay() const {
    return fMillisInDay;
}

U_NAMESPACE_END

#endif /* #if !UCONFIG_NO_FORMATTING */

//eof