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 FLclCalendar.cpp
19 * @brief This is the implementation file for Calendar class.
21 #include <FBaseSysLog.h>
22 #include <FApp_AppInfo.h>
23 #include <FLclCalendar.h>
24 #include <FLclGregorianCalendar.h>
25 #include <FLclLocale.h>
26 #include <FLclTimeZone.h>
28 #include "FLcl_CalendarImpl.h"
29 #include "FLcl_LocaleImpl.h"
31 using namespace Tizen::Base;
33 namespace Tizen { namespace Locales
36 Calendar::Calendar(void)
40 , _areFieldsSet(false)
41 , _areAllFieldsSet(false)
44 , _isConstructed(false)
45 , _pCalendarImpl(null)
47 for (int i = 0; i < TIME_FIELD_FIELD_COUNT; i++)
56 Calendar::Construct(void)
58 return Construct(TimeZone::GetGmtTimeZone(), Locale(LANGUAGE_ENG, COUNTRY_GB));
62 Calendar::Construct(const Calendar& other)
64 // Object is not allowed to construct twice
65 SysAssertf(_isConstructed == false,
66 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
68 for (int i = 0; i < TIME_FIELD_FIELD_COUNT; i++)
70 _timeFields[i] = other._timeFields[i];
71 _stamp[i] = other._stamp[i];
72 _isSet[i] = other._isSet[i];
76 _timeZone = other._timeZone;
77 _isTimeSet = other._isTimeSet;
78 _areFieldsSet = other._areFieldsSet;
79 _areAllFieldsSet = other._areAllFieldsSet;
80 _nextStamp = other._nextStamp;
81 _isLenient = other._isLenient;
82 _isConstructed = true;
88 Calendar::Construct(const TimeZone& timezone, const Locale& locale)
90 // Object is not allowed to construct twice
91 SysAssertf(_isConstructed == false,
92 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
94 result r = E_INVALID_ARG;
95 if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
97 r = E_UNSUPPORTED_OPERATION;
100 SysTryReturnResult(NID_LCL, _LocaleImpl::IsSupported(locale), r, "Given locale is not supported");
102 _timeZone = timezone;
103 _nextStamp = MINIMUM_USER_STAMP;
105 _isConstructed = true;
109 Calendar::~Calendar(void)
114 Calendar::CreateInstanceN(CalendarType calendarType)
116 return _CalendarImpl::CreateCalendarInstanceN(calendarType);
120 Calendar::CreateInstanceN(const TimeZone& timeZone, CalendarType calendarType)
122 return _CalendarImpl::CreateCalendarInstanceN(timeZone, calendarType);
126 Calendar::CreateInstanceN(const Locale& locale, CalendarType calendarType)
128 return _CalendarImpl::CreateCalendarInstanceN(locale, calendarType);
132 Calendar::CreateInstanceN(const TimeZone& timeZone, const Locale& locale, CalendarType calendarType)
134 return _CalendarImpl::CreateCalendarInstanceN(timeZone, locale, calendarType);
138 Calendar::After(const Calendar& otherCalendar, bool& after)
140 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
142 result r = E_INVALID_ARG;
144 if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
148 SysTryReturnResult(NID_LCL, otherCalendar._pCalendarImpl, r, "Invalid argument is used. otherCalendar instance is invalid");
149 return _pCalendarImpl->AfterImpl(*otherCalendar._pCalendarImpl, after);
153 Calendar::Before(const Calendar& otherCalendar, bool& before)
155 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
157 result r = E_INVALID_ARG;
159 if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
163 SysTryReturnResult(NID_LCL, otherCalendar._pCalendarImpl, r, "Invalid argument is used. otherCalendar instance is invalid");
164 return _pCalendarImpl->BeforeImpl(*otherCalendar._pCalendarImpl, before);
168 Calendar::Clear(void)
170 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
171 return _pCalendarImpl->ClearImpl();
175 Calendar::Clear(TimeField field)
177 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
178 return _pCalendarImpl->ClearImpl(field);
182 Calendar::Equals(const Object& obj) const
184 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
186 const Calendar* pOtherInstance = dynamic_cast< const Calendar* >(&obj);
187 if ((pOtherInstance == null) || (pOtherInstance->_pCalendarImpl == null) || GetType() != pOtherInstance->GetType())
192 return _pCalendarImpl->EqualsImpl(*pOtherInstance->_pCalendarImpl);
196 Calendar::GetHashCode(void) const
198 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
199 return _pCalendarImpl->GetHashCodeImpl();
203 Calendar::GetActualMaxTimeField(TimeField field) const
205 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
206 return _pCalendarImpl->GetActualMaxTimeFieldImpl(field);
210 Calendar::GetActualMinTimeField(TimeField field) const
212 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
213 return _pCalendarImpl->GetActualMinTimeFieldImpl(field);
217 Calendar::GetFirstDayOfWeek(void) const
219 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
220 return _pCalendarImpl->GetFirstDayOfWeekImpl();
224 Calendar::GetGreatestMinTimeField(TimeField field) const
226 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
227 return _pCalendarImpl->GetGreatestMinTimeFieldImpl(field);
231 Calendar::GetLeastMaxTimeField(TimeField field) const
233 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
234 return _pCalendarImpl->GetLeastMaxTimeFieldImpl(field);
238 Calendar::GetMaxTimeField(TimeField field) const
240 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
241 return _pCalendarImpl->GetMaxTimeFieldImpl(field);
245 Calendar::GetMinTimeField(TimeField field) const
247 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
248 return _pCalendarImpl->GetMinTimeFieldImpl(field);
252 Calendar::GetMinDaysInFirstWeek(void) const
254 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
255 return _pCalendarImpl->GetMinDaysInFirstWeekImpl();
259 Calendar::GetTime(void) const
261 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
262 return _pCalendarImpl->GetTimeImpl();
266 Calendar::GetTimeField(TimeField field) const
268 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
269 return _pCalendarImpl->GetTimeFieldImpl(field);
273 Calendar::GetTimeZone(void) const
275 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
276 return _pCalendarImpl->GetTimeZoneImpl();
280 Calendar::IsLenient(void) const
282 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
283 return _pCalendarImpl->IsLenientImpl();
287 Calendar::IsSet(TimeField field) const
289 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
290 return _pCalendarImpl->IsSetImpl(field);
294 Calendar::Roll(TimeField field, int amount)
296 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
297 return _pCalendarImpl->RollImpl(field, amount);
301 Calendar::SetTime(const DateTime& dateTime)
303 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
304 return _pCalendarImpl->SetTimeImpl(dateTime);
308 Calendar::SetTime(int year, int month, int day, int hour, int minute, int second)
310 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
311 return _pCalendarImpl->SetTimeImpl(year, month, day, hour, minute, second);
315 Calendar::SetTimeField(TimeField field, int value)
317 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
318 return _pCalendarImpl->SetTimeFieldImpl(field, value);
322 Calendar::SetFirstDayOfWeek(DayOfWeek dayOfWeek)
324 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
325 return _pCalendarImpl->SetFirstDayOfWeekImpl(dayOfWeek);
329 Calendar::SetLenient(bool lenient)
331 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
332 return _pCalendarImpl->SetLenientImpl(lenient);
336 Calendar::SetMinDaysInFirstWeek(short value)
338 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
339 return _pCalendarImpl->SetMinDaysInFirstWeekImpl(value);
343 Calendar::SetTimeZone(const TimeZone& timeZone)
345 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
346 return _pCalendarImpl->SetTimeZoneImpl(timeZone);
350 Calendar::GetTimeInMillisec(long long& millisec) const
352 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
353 return _pCalendarImpl->GetTimeInMillisecImpl(millisec);
357 Calendar::SetTimeInMillisec(long long millisec)
359 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
360 return _pCalendarImpl->SetTimeInMillisecImpl(millisec);
364 Calendar::IsEquivalentTo(const Calendar& calendar) const
366 bool isEquivalent = ((IsLenient() == calendar.IsLenient()) &&
367 (GetFirstDayOfWeek() == calendar.GetFirstDayOfWeek()) &&
368 (GetMinDaysInFirstWeek() == calendar.GetMinDaysInFirstWeek()) &&
369 (GetTimeZone() == calendar.GetTimeZone()) &&
370 (GetType() == calendar.GetType()));