N_SE-53194 : fix AppControl::Stop() without listener
[platform/framework/native/appfw.git] / src / locales / FLclTimeRule.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file            FLclTimeRule.cpp
19  * @brief           This file contains implementation of TimeRule class
20  */
21
22 #include <FLclTimeRule.h>
23 #include <FBaseResult.h>
24 #include <FBaseInteger.h>
25
26 using namespace Tizen::Base;
27 using namespace Tizen::Locales;
28 using namespace Tizen::System;
29
30 namespace Tizen { namespace Locales
31 {
32
33 /**
34  * @enum DstRuleMode
35  * Possible DST rule mode
36  */
37 enum DstRuleMode
38 {
39         EXACT_DAY = 0,
40         DAY_OF_WEEK_IN_MONTH,
41         AFTER_THE_SPECIFIED_DAY,
42         BEFORE_THE_SPECIFIED_DAY,
43         BACKWARD_FROM_END_OF_MONTH
44 };
45
46 TimeRule::TimeRule(const TimeRule& timeRule)
47         : __pTimeRuleImpl(null)
48 {
49         __month = timeRule.__month;
50         __day = timeRule.__day;
51         __week = timeRule.__week;
52         __dayOfWeek = timeRule.__dayOfWeek;
53         __hour = timeRule.__hour;
54         __minute = timeRule.__minute;
55         __timeMode = timeRule.__timeMode;
56         __onOrAfterDay = timeRule.__onOrAfterDay;
57 }
58
59
60 TimeRule::~TimeRule(void)
61 {
62 }
63
64
65 // Exact day
66 TimeRule::TimeRule(Month month, int day, int hour, int minute, TimeMode timeMode)
67         : __pTimeRuleImpl(null)
68 {
69         SetValue(month, day, WEEK_UNDEFINED, DAY_OF_WEEK_UNDEFINED, true, hour, minute, timeMode);
70 }
71
72
73 // The day of week of x-th week of month / The Last day of week of month
74 TimeRule::TimeRule(Month month, Week week, DayOfWeek dayOfWeek, int hour, int minute, TimeMode timeMode)
75         : __pTimeRuleImpl(null)
76 {
77         SetValue(month, DAY_UNDEFINED, week, dayOfWeek, true, hour, minute, timeMode);
78 }
79
80
81 // Day of week on or before/after day of month
82 TimeRule::TimeRule(Month month, int day, DayOfWeek dayOfWeek, bool onOrAfterDay, int hour, int minute, TimeMode timeMode)
83         : __pTimeRuleImpl(null)
84 {
85         SetValue(month, day, WEEK_UNDEFINED, dayOfWeek, onOrAfterDay, hour, minute, timeMode);
86 }
87
88
89 // Internal construction method
90 void
91 TimeRule::SetValue(Month month, int day, Week week, DayOfWeek dayOfWeek, bool onOrAfterDay, int hour, int minute,
92                                    TimeMode timeMode)
93 {
94         __month = month;
95         __day = day;
96         __week = week;
97         __dayOfWeek = dayOfWeek;
98         __hour = hour;
99         __minute = minute;
100         __timeMode = timeMode;
101         __onOrAfterDay = onOrAfterDay;
102 }
103
104
105 Month
106 TimeRule::GetMonth(void) const
107 {
108         return __month;
109 }
110
111
112 int
113 TimeRule::GetDay(void) const
114 {
115         return __day;
116 }
117
118
119 Week
120 TimeRule::GetWeek(void) const
121 {
122         return __week;
123 }
124
125
126 DayOfWeek
127 TimeRule::GetDayOfWeek(void) const
128 {
129         return __dayOfWeek;
130 }
131
132
133 int
134 TimeRule::GetHour(void) const
135 {
136         return __hour;
137 }
138
139 int
140 TimeRule::GetMinute(void) const
141 {
142         return __minute;
143 }
144
145
146 TimeMode
147 TimeRule::GetTimeMode(void) const
148 {
149         return __timeMode;
150 }
151
152
153 bool
154 TimeRule::IsOnOrAfterDay(void) const
155 {
156         return __onOrAfterDay;
157 }
158
159 TimeRule&
160 TimeRule::operator =(const TimeRule& timeRule)
161 {
162         if (&timeRule != this)
163         {
164                 __month = timeRule.__month;
165                 __day = timeRule.__day;
166                 __week = timeRule.__week;
167                 __dayOfWeek = timeRule.__dayOfWeek;
168                 __hour = timeRule.__hour;
169                 __minute = timeRule.__minute;
170                 __timeMode = timeRule.__timeMode;
171                 __onOrAfterDay = timeRule.__onOrAfterDay;
172         }
173         return *this;
174 }
175
176 int
177 TimeRule::GetRuleMode(void) const
178 {
179         DstRuleMode ruleMode;
180
181         if (DAY_UNDEFINED != __day)
182         {
183                 if (__dayOfWeek == DAY_OF_WEEK_UNDEFINED)
184                 {
185                         ruleMode = EXACT_DAY;
186                 }
187                 else
188                 {
189                         ruleMode = __onOrAfterDay ? AFTER_THE_SPECIFIED_DAY : BEFORE_THE_SPECIFIED_DAY;
190                 }
191         }
192         else
193         {
194                 ruleMode = DAY_OF_WEEK_IN_MONTH;
195         }
196
197         return static_cast< int >(ruleMode);
198 }
199
200 bool
201 TimeRule::Equals(const Object& obj) const
202 {
203         const TimeRule* pOtherTimeRule = dynamic_cast< const TimeRule* >(&obj);
204         if (pOtherTimeRule)
205         {
206                 if (__month == pOtherTimeRule->__month
207                         && __day == pOtherTimeRule->__day
208                         && __week == pOtherTimeRule->__week
209                         && __dayOfWeek == pOtherTimeRule->__dayOfWeek
210                         && __hour == pOtherTimeRule->__hour
211                         && __minute == pOtherTimeRule->__minute
212                         && __timeMode == pOtherTimeRule->__timeMode
213                         && __onOrAfterDay == pOtherTimeRule->__onOrAfterDay
214                         )
215                 {
216                         return true;
217                 }
218
219         }
220         return false;
221 }
222
223 int
224 TimeRule::GetHashCode(void) const
225 {
226         Integer value = __month + __day + __week + __dayOfWeek + __hour + __minute + __timeMode + __onOrAfterDay;
227         return value.GetHashCode();
228 }
229
230
231 }} // Tizen::Locales