2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FLclCalendar.cpp
20 * @brief This is the implementation file for Calendar class.
22 #include <FBaseSysLog.h>
23 #include <FApp_AppInfo.h>
24 #include <FLclCalendar.h>
25 #include <FLclGregorianCalendar.h>
26 #include <FLclLocale.h>
27 #include <FLclTimeZone.h>
29 #include "FLcl_CalendarImpl.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;
96 if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
98 r = E_UNSUPPORTED_OPERATION;
101 SysTryReturnResult(NID_LCL, locale.GetLanguageCode() != LANGUAGE_INVALID,
102 r, "Invalid argument is used. Language code is invalid. Given locale is not supported");
104 SysTryReturnResult(NID_LCL, locale.GetCountryCode() != COUNTRY_INVALID,
105 r, "Invalid argument is used. Country code is invalid. Given locale is not supported");
107 _timeZone = timezone;
108 _nextStamp = MINIMUM_USER_STAMP;
110 _isConstructed = true;
114 Calendar::~Calendar(void)
119 Calendar::CreateInstanceN(CalendarType calendarType)
121 return _CalendarImpl::CreateCalendarInstanceN(calendarType);
125 Calendar::CreateInstanceN(const TimeZone& timeZone, CalendarType calendarType)
127 return _CalendarImpl::CreateCalendarInstanceN(timeZone, calendarType);
131 Calendar::CreateInstanceN(const Locale& locale, CalendarType calendarType)
133 return _CalendarImpl::CreateCalendarInstanceN(locale, calendarType);
137 Calendar::CreateInstanceN(const TimeZone& timeZone, const Locale& locale, CalendarType calendarType)
139 return _CalendarImpl::CreateCalendarInstanceN(timeZone, locale, calendarType);
143 Calendar::After(const Calendar& otherCalendar, bool& after)
145 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
147 result r = E_INVALID_ARG;
149 if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
153 SysTryReturnResult(NID_LCL, otherCalendar._pCalendarImpl, r, "Invalid argument is used. otherCalendar instance is invalid");
154 return _pCalendarImpl->After(*otherCalendar._pCalendarImpl, after);
158 Calendar::Before(const Calendar& otherCalendar, bool& before)
160 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
162 result r = E_INVALID_ARG;
164 if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
168 SysTryReturnResult(NID_LCL, otherCalendar._pCalendarImpl, r, "Invalid argument is used. otherCalendar instance is invalid");
169 return _pCalendarImpl->Before(*otherCalendar._pCalendarImpl, before);
173 Calendar::Clear(void)
175 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
176 return _pCalendarImpl->ClearImpl();
180 Calendar::Clear(TimeField field)
182 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
183 return _pCalendarImpl->ClearImpl(field);
187 Calendar::Equals(const Object& obj) const
189 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
191 const Calendar* pOtherInstance = dynamic_cast< const Calendar* >(&obj);
192 if ((pOtherInstance == null) || (pOtherInstance->_pCalendarImpl == null))
197 return _pCalendarImpl->Equals(*pOtherInstance->_pCalendarImpl);
201 Calendar::GetHashCode(void) const
203 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
204 return _pCalendarImpl->GetHashCode();
208 Calendar::GetActualMaxTimeField(TimeField field) const
210 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
211 return _pCalendarImpl->GetActualMaxTimeField(field);
215 Calendar::GetActualMinTimeField(TimeField field) const
217 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
218 return _pCalendarImpl->GetActualMinTimeField(field);
222 Calendar::GetFirstDayOfWeek(void) const
224 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
225 return _pCalendarImpl->GetFirstDayOfWeekImpl();
229 Calendar::GetGreatestMinTimeField(TimeField field) const
231 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
232 return _pCalendarImpl->GetGreatestMinTimeField(field);
236 Calendar::GetLeastMaxTimeField(TimeField field) const
238 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
239 return _pCalendarImpl->GetLeastMaxTimeField(field);
243 Calendar::GetMaxTimeField(TimeField field) const
245 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
246 return _pCalendarImpl->GetMaxTimeField(field);
250 Calendar::GetMinTimeField(TimeField field) const
252 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
253 return _pCalendarImpl->GetMinTimeField(field);
257 Calendar::GetMinDaysInFirstWeek(void) const
259 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
260 return _pCalendarImpl->GetMinDaysInFirstWeekImpl();
264 Calendar::GetTime(void) const
266 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
267 return _pCalendarImpl->GetTimeImpl();
271 Calendar::GetTimeField(TimeField field) const
273 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
274 return _pCalendarImpl->GetTimeFieldImpl(field);
278 Calendar::GetTimeZone(void) const
280 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
281 return _pCalendarImpl->GetTimeZoneImpl();
285 Calendar::IsLenient(void) const
287 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
288 return _pCalendarImpl->IsLenientImpl();
292 Calendar::IsSet(TimeField field) const
294 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
295 return _pCalendarImpl->IsSetImpl(field);
299 Calendar::Roll(TimeField field, int amount)
301 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
302 return _pCalendarImpl->Roll(field, amount);
306 Calendar::SetTime(const DateTime& dateTime)
308 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
309 return _pCalendarImpl->SetTimeImpl(dateTime);
313 Calendar::SetTime(int year, int month, int day, int hour, int minute, int second)
315 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
316 return _pCalendarImpl->SetTimeImpl(year, month, day, hour, minute, second);
320 Calendar::SetTimeField(TimeField field, int value)
322 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
323 return _pCalendarImpl->SetTimeFieldImpl(field, value);
327 Calendar::SetFirstDayOfWeek(DayOfWeek dayOfWeek)
329 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
330 return _pCalendarImpl->SetFirstDayOfWeekImpl(dayOfWeek);
334 Calendar::SetLenient(bool lenient)
336 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
337 return _pCalendarImpl->SetLenientImpl(lenient);
341 Calendar::SetMinDaysInFirstWeek(short value)
343 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
344 return _pCalendarImpl->SetMinDaysInFirstWeekImpl(value);
348 Calendar::SetTimeZone(const TimeZone& timeZone)
350 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
351 return _pCalendarImpl->SetTimeZoneImpl(timeZone);
355 Calendar::GetTimeInMillisec(long long& millisec) const
357 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
358 return _pCalendarImpl->GetTimeInMillisecImpl(millisec);
362 Calendar::SetTimeInMillisec(long long millisec)
364 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
365 return _pCalendarImpl->SetTimeInMillisecImpl(millisec);
369 Calendar::IsEquivalentTo(const Calendar& calendar) const
371 bool isEquivalent = ((_isLenient == calendar.IsLenient()) &&
372 (GetFirstDayOfWeek() == calendar.GetFirstDayOfWeek()) &&
373 (GetMinDaysInFirstWeek() == calendar.GetMinDaysInFirstWeek()) &&
374 (_timeZone == calendar.GetTimeZone()));