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"
30 #include "FLcl_LocaleImpl.h"
32 using namespace Tizen::Base;
34 namespace Tizen { namespace Locales
37 Calendar::Calendar(void)
41 , _areFieldsSet(false)
42 , _areAllFieldsSet(false)
45 , _isConstructed(false)
46 , _pCalendarImpl(null)
48 for (int i = 0; i < TIME_FIELD_FIELD_COUNT; i++)
57 Calendar::Construct(void)
59 return Construct(TimeZone::GetGmtTimeZone(), Locale(LANGUAGE_ENG, COUNTRY_GB));
63 Calendar::Construct(const Calendar& other)
65 // Object is not allowed to construct twice
66 SysAssertf(_isConstructed == false,
67 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
69 for (int i = 0; i < TIME_FIELD_FIELD_COUNT; i++)
71 _timeFields[i] = other._timeFields[i];
72 _stamp[i] = other._stamp[i];
73 _isSet[i] = other._isSet[i];
77 _timeZone = other._timeZone;
78 _isTimeSet = other._isTimeSet;
79 _areFieldsSet = other._areFieldsSet;
80 _areAllFieldsSet = other._areAllFieldsSet;
81 _nextStamp = other._nextStamp;
82 _isLenient = other._isLenient;
83 _isConstructed = true;
89 Calendar::Construct(const TimeZone& timezone, const Locale& locale)
91 // Object is not allowed to construct twice
92 SysAssertf(_isConstructed == false,
93 "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
95 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, _LocaleImpl::IsSupported(locale), r, "Given locale is not supported");
103 _timeZone = timezone;
104 _nextStamp = MINIMUM_USER_STAMP;
106 _isConstructed = true;
110 Calendar::~Calendar(void)
115 Calendar::CreateInstanceN(CalendarType calendarType)
117 return _CalendarImpl::CreateCalendarInstanceN(calendarType);
121 Calendar::CreateInstanceN(const TimeZone& timeZone, CalendarType calendarType)
123 return _CalendarImpl::CreateCalendarInstanceN(timeZone, calendarType);
127 Calendar::CreateInstanceN(const Locale& locale, CalendarType calendarType)
129 return _CalendarImpl::CreateCalendarInstanceN(locale, calendarType);
133 Calendar::CreateInstanceN(const TimeZone& timeZone, const Locale& locale, CalendarType calendarType)
135 return _CalendarImpl::CreateCalendarInstanceN(timeZone, locale, calendarType);
139 Calendar::After(const Calendar& otherCalendar, bool& after)
141 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
143 result r = E_INVALID_ARG;
145 if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
149 SysTryReturnResult(NID_LCL, otherCalendar._pCalendarImpl, r, "Invalid argument is used. otherCalendar instance is invalid");
150 return _pCalendarImpl->After(*otherCalendar._pCalendarImpl, after);
154 Calendar::Before(const Calendar& otherCalendar, bool& before)
156 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
158 result r = E_INVALID_ARG;
160 if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
164 SysTryReturnResult(NID_LCL, otherCalendar._pCalendarImpl, r, "Invalid argument is used. otherCalendar instance is invalid");
165 return _pCalendarImpl->Before(*otherCalendar._pCalendarImpl, before);
169 Calendar::Clear(void)
171 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
172 return _pCalendarImpl->ClearImpl();
176 Calendar::Clear(TimeField field)
178 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
179 return _pCalendarImpl->ClearImpl(field);
183 Calendar::Equals(const Object& obj) const
185 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
187 const Calendar* pOtherInstance = dynamic_cast< const Calendar* >(&obj);
188 if ((pOtherInstance == null) || (pOtherInstance->_pCalendarImpl == null) || GetType() != pOtherInstance->GetType())
193 return _pCalendarImpl->Equals(*pOtherInstance->_pCalendarImpl);
197 Calendar::GetHashCode(void) const
199 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
200 return _pCalendarImpl->GetHashCode();
204 Calendar::GetActualMaxTimeField(TimeField field) const
206 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
207 return _pCalendarImpl->GetActualMaxTimeFieldImpl(field);
211 Calendar::GetActualMinTimeField(TimeField field) const
213 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
214 return _pCalendarImpl->GetActualMinTimeFieldImpl(field);
218 Calendar::GetFirstDayOfWeek(void) const
220 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
221 return _pCalendarImpl->GetFirstDayOfWeekImpl();
225 Calendar::GetGreatestMinTimeField(TimeField field) const
227 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
228 return _pCalendarImpl->GetGreatestMinTimeField(field);
232 Calendar::GetLeastMaxTimeField(TimeField field) const
234 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
235 return _pCalendarImpl->GetLeastMaxTimeField(field);
239 Calendar::GetMaxTimeField(TimeField field) const
241 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
242 return _pCalendarImpl->GetMaxTimeField(field);
246 Calendar::GetMinTimeField(TimeField field) const
248 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
249 return _pCalendarImpl->GetMinTimeField(field);
253 Calendar::GetMinDaysInFirstWeek(void) const
255 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
256 return _pCalendarImpl->GetMinDaysInFirstWeekImpl();
260 Calendar::GetTime(void) const
262 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
263 return _pCalendarImpl->GetTimeImpl();
267 Calendar::GetTimeField(TimeField field) const
269 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
270 return _pCalendarImpl->GetTimeFieldImpl(field);
274 Calendar::GetTimeZone(void) const
276 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
277 return _pCalendarImpl->GetTimeZoneImpl();
281 Calendar::IsLenient(void) const
283 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
284 return _pCalendarImpl->IsLenientImpl();
288 Calendar::IsSet(TimeField field) const
290 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
291 return _pCalendarImpl->IsSetImpl(field);
295 Calendar::Roll(TimeField field, int amount)
297 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
298 return _pCalendarImpl->RollImpl(field, amount);
302 Calendar::SetTime(const DateTime& dateTime)
304 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
305 return _pCalendarImpl->SetTimeImpl(dateTime);
309 Calendar::SetTime(int year, int month, int day, int hour, int minute, int second)
311 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
312 return _pCalendarImpl->SetTimeImpl(year, month, day, hour, minute, second);
316 Calendar::SetTimeField(TimeField field, int value)
318 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
319 return _pCalendarImpl->SetTimeFieldImpl(field, value);
323 Calendar::SetFirstDayOfWeek(DayOfWeek dayOfWeek)
325 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
326 return _pCalendarImpl->SetFirstDayOfWeekImpl(dayOfWeek);
330 Calendar::SetLenient(bool lenient)
332 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
333 return _pCalendarImpl->SetLenientImpl(lenient);
337 Calendar::SetMinDaysInFirstWeek(short value)
339 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
340 return _pCalendarImpl->SetMinDaysInFirstWeekImpl(value);
344 Calendar::SetTimeZone(const TimeZone& timeZone)
346 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
347 return _pCalendarImpl->SetTimeZoneImpl(timeZone);
351 Calendar::GetTimeInMillisec(long long& millisec) const
353 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
354 return _pCalendarImpl->GetTimeInMillisecImpl(millisec);
358 Calendar::SetTimeInMillisec(long long millisec)
360 SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
361 return _pCalendarImpl->SetTimeInMillisecImpl(millisec);
365 Calendar::IsEquivalentTo(const Calendar& calendar) const
367 bool isEquivalent = ((_isLenient == calendar.IsLenient()) &&
368 (GetFirstDayOfWeek() == calendar.GetFirstDayOfWeek()) &&
369 (GetMinDaysInFirstWeek() == calendar.GetMinDaysInFirstWeek()) &&
370 (_timeZone == calendar.GetTimeZone()));