2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FLclTimeRule.cpp
19 * @brief This file contains implementation of TimeRule class
22 #include <FLclTimeRule.h>
23 #include <FBaseResult.h>
24 #include <FBaseInteger.h>
26 using namespace Tizen::Base;
27 using namespace Tizen::Locales;
28 using namespace Tizen::System;
30 namespace Tizen { namespace Locales
35 * Possible DST rule mode
41 AFTER_THE_SPECIFIED_DAY,
42 BEFORE_THE_SPECIFIED_DAY,
43 BACKWARD_FROM_END_OF_MONTH
46 TimeRule::TimeRule(const TimeRule& timeRule)
47 : __pTimeRuleImpl(null)
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;
60 TimeRule::~TimeRule(void)
66 TimeRule::TimeRule(Month month, int day, int hour, int minute, TimeMode timeMode)
67 : __pTimeRuleImpl(null)
69 SetValue(month, day, WEEK_UNDEFINED, DAY_OF_WEEK_UNDEFINED, true, hour, minute, timeMode);
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)
77 SetValue(month, DAY_UNDEFINED, week, dayOfWeek, true, hour, minute, timeMode);
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)
85 SetValue(month, day, WEEK_UNDEFINED, dayOfWeek, onOrAfterDay, hour, minute, timeMode);
89 // Internal construction method
91 TimeRule::SetValue(Month month, int day, Week week, DayOfWeek dayOfWeek, bool onOrAfterDay, int hour, int minute,
97 __dayOfWeek = dayOfWeek;
100 __timeMode = timeMode;
101 __onOrAfterDay = onOrAfterDay;
106 TimeRule::GetMonth(void) const
113 TimeRule::GetDay(void) const
120 TimeRule::GetWeek(void) const
127 TimeRule::GetDayOfWeek(void) const
134 TimeRule::GetHour(void) const
140 TimeRule::GetMinute(void) const
147 TimeRule::GetTimeMode(void) const
154 TimeRule::IsOnOrAfterDay(void) const
156 return __onOrAfterDay;
160 TimeRule::operator =(const TimeRule& timeRule)
162 if (&timeRule != this)
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;
177 TimeRule::GetRuleMode(void) const
179 DstRuleMode ruleMode;
181 if (DAY_UNDEFINED != __day)
183 if (__dayOfWeek == DAY_OF_WEEK_UNDEFINED)
185 ruleMode = EXACT_DAY;
189 ruleMode = __onOrAfterDay ? AFTER_THE_SPECIFIED_DAY : BEFORE_THE_SPECIFIED_DAY;
194 ruleMode = DAY_OF_WEEK_IN_MONTH;
197 return static_cast< int >(ruleMode);
201 TimeRule::Equals(const Object& obj) const
203 const TimeRule* pOtherTimeRule = dynamic_cast< const TimeRule* >(&obj);
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
224 TimeRule::GetHashCode(void) const
226 Integer value = __month + __day + __week + __dayOfWeek + __hour + __minute + __timeMode + __onOrAfterDay;
227 return value.GetHashCode();