Modified an api call flow
[platform/framework/native/appfw.git] / src / locales / FLclCalendar.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19 * @file         FLclCalendar.cpp
20 * @brief        This is the implementation file for Calendar class.
21 */
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>
28
29 #include "FLcl_CalendarImpl.h"
30 #include "FLcl_LocaleImpl.h"
31
32 using namespace Tizen::Base;
33
34 namespace Tizen { namespace Locales
35 {
36
37 Calendar::Calendar(void)
38         : _time(0)
39         , _timeZone()
40         , _isTimeSet(false)
41         , _areFieldsSet(false)
42         , _areAllFieldsSet(false)
43         , _nextStamp(0)
44         , _isLenient(true)
45         , _isConstructed(false)
46         , _pCalendarImpl(null)
47 {
48         for (int i = 0; i < TIME_FIELD_FIELD_COUNT; i++)
49         {
50                 _timeFields[i] = 0;
51                 _stamp[i] = UNSET;
52                 _isSet[i] = false;
53         }
54 }
55
56 result
57 Calendar::Construct(void)
58 {
59         return Construct(TimeZone::GetGmtTimeZone(), Locale(LANGUAGE_ENG, COUNTRY_GB));
60 }
61
62 result
63 Calendar::Construct(const Calendar& other)
64 {
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");
68
69         for (int i = 0; i < TIME_FIELD_FIELD_COUNT; i++)
70         {
71                 _timeFields[i] = other._timeFields[i];
72                 _stamp[i] = other._stamp[i];
73                 _isSet[i] = other._isSet[i];
74         }
75
76         _time = other._time;
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;
84
85         return E_SUCCESS;
86 }
87
88 result
89 Calendar::Construct(const TimeZone& timezone, const Locale& locale)
90 {
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");
94
95         result r = E_INVALID_ARG;
96     if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
97     {
98             r = E_UNSUPPORTED_OPERATION;
99     }
100
101         SysTryReturnResult(NID_LCL, _LocaleImpl::IsSupported(locale), r, "Given locale is not supported");
102
103         _timeZone = timezone;
104         _nextStamp = MINIMUM_USER_STAMP;
105         _isLenient = true;
106         _isConstructed = true;
107         return E_SUCCESS;
108 }
109
110 Calendar::~Calendar(void)
111 {
112 }
113
114 Calendar*
115 Calendar::CreateInstanceN(CalendarType calendarType)
116 {
117         return _CalendarImpl::CreateCalendarInstanceN(calendarType);
118 }
119
120 Calendar*
121 Calendar::CreateInstanceN(const TimeZone& timeZone, CalendarType calendarType)
122 {
123         return _CalendarImpl::CreateCalendarInstanceN(timeZone, calendarType);
124 }
125
126 Calendar*
127 Calendar::CreateInstanceN(const Locale& locale, CalendarType calendarType)
128 {
129         return _CalendarImpl::CreateCalendarInstanceN(locale, calendarType);
130 }
131
132 Calendar*
133 Calendar::CreateInstanceN(const TimeZone& timeZone, const Locale& locale, CalendarType calendarType)
134 {
135         return _CalendarImpl::CreateCalendarInstanceN(timeZone, locale, calendarType);
136 }
137
138 result
139 Calendar::After(const Calendar& otherCalendar, bool& after)
140 {
141         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
142
143         result r = E_INVALID_ARG;
144
145         if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
146         {
147                 r = E_INVALID_STATE;
148         }
149         SysTryReturnResult(NID_LCL, otherCalendar._pCalendarImpl, r, "Invalid argument is used. otherCalendar instance is invalid");
150         return _pCalendarImpl->After(*otherCalendar._pCalendarImpl, after);
151 }
152
153 result
154 Calendar::Before(const Calendar& otherCalendar, bool& before)
155 {
156         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
157
158         result r = E_INVALID_ARG;
159
160         if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
161         {
162                 r = E_INVALID_STATE;
163         }
164         SysTryReturnResult(NID_LCL, otherCalendar._pCalendarImpl, r, "Invalid argument is used. otherCalendar instance is invalid");
165         return _pCalendarImpl->Before(*otherCalendar._pCalendarImpl, before);
166 }
167
168 result
169 Calendar::Clear(void)
170 {
171         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
172         return _pCalendarImpl->ClearImpl();
173 }
174
175 result
176 Calendar::Clear(TimeField field)
177 {
178         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
179         return _pCalendarImpl->ClearImpl(field);
180 }
181
182 bool
183 Calendar::Equals(const Object& obj) const
184 {
185         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
186
187         const Calendar* pOtherInstance = dynamic_cast< const Calendar* >(&obj);
188         if ((pOtherInstance == null) || (pOtherInstance->_pCalendarImpl == null) || GetType() != pOtherInstance->GetType())
189         {
190                 return false;
191         }
192
193         return _pCalendarImpl->Equals(*pOtherInstance->_pCalendarImpl);
194 }
195
196 int
197 Calendar::GetHashCode(void) const
198 {
199         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
200         return _pCalendarImpl->GetHashCode();
201 }
202
203 int
204 Calendar::GetActualMaxTimeField(TimeField field) const
205 {
206         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
207         return _pCalendarImpl->GetActualMaxTimeFieldImpl(field);
208 }
209
210 int
211 Calendar::GetActualMinTimeField(TimeField field) const
212 {
213         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
214         return _pCalendarImpl->GetActualMinTimeFieldImpl(field);
215 }
216
217 int
218 Calendar::GetFirstDayOfWeek(void) const
219 {
220         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
221         return _pCalendarImpl->GetFirstDayOfWeekImpl();
222 }
223
224 int
225 Calendar::GetGreatestMinTimeField(TimeField field) const
226 {
227         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
228         return _pCalendarImpl->GetGreatestMinTimeField(field);
229 }
230
231 int
232 Calendar::GetLeastMaxTimeField(TimeField field) const
233 {
234         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
235         return _pCalendarImpl->GetLeastMaxTimeField(field);
236 }
237
238 int
239 Calendar::GetMaxTimeField(TimeField field) const
240 {
241         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
242         return _pCalendarImpl->GetMaxTimeField(field);
243 }
244
245 int
246 Calendar::GetMinTimeField(TimeField field) const
247 {
248         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
249         return _pCalendarImpl->GetMinTimeField(field);
250 }
251
252 int
253 Calendar::GetMinDaysInFirstWeek(void) const
254 {
255         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
256         return _pCalendarImpl->GetMinDaysInFirstWeekImpl();
257 }
258
259 DateTime
260 Calendar::GetTime(void) const
261 {
262         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
263         return _pCalendarImpl->GetTimeImpl();
264 }
265
266 int
267 Calendar::GetTimeField(TimeField field) const
268 {
269         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
270         return _pCalendarImpl->GetTimeFieldImpl(field);
271 }
272
273 TimeZone
274 Calendar::GetTimeZone(void) const
275 {
276         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
277         return _pCalendarImpl->GetTimeZoneImpl();
278 }
279
280 bool
281 Calendar::IsLenient(void) const
282 {
283         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
284         return _pCalendarImpl->IsLenientImpl();
285 }
286
287 bool
288 Calendar::IsSet(TimeField field) const
289 {
290         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
291         return _pCalendarImpl->IsSetImpl(field);
292 }
293
294 result
295 Calendar::Roll(TimeField field, int amount)
296 {
297         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
298         return _pCalendarImpl->RollImpl(field, amount);
299 }
300
301 result
302 Calendar::SetTime(const DateTime& dateTime)
303 {
304         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
305         return _pCalendarImpl->SetTimeImpl(dateTime);
306 }
307
308 result
309 Calendar::SetTime(int year, int month, int day, int hour, int minute, int second)
310 {
311         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
312         return _pCalendarImpl->SetTimeImpl(year, month, day, hour, minute, second);
313 }
314
315 result
316 Calendar::SetTimeField(TimeField field, int value)
317 {
318         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
319         return _pCalendarImpl->SetTimeFieldImpl(field, value);
320 }
321
322 result
323 Calendar::SetFirstDayOfWeek(DayOfWeek dayOfWeek)
324 {
325         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
326         return _pCalendarImpl->SetFirstDayOfWeekImpl(dayOfWeek);
327 }
328
329 result
330 Calendar::SetLenient(bool lenient)
331 {
332         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
333         return _pCalendarImpl->SetLenientImpl(lenient);
334 }
335
336 result
337 Calendar::SetMinDaysInFirstWeek(short value)
338 {
339         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
340         return _pCalendarImpl->SetMinDaysInFirstWeekImpl(value);
341 }
342
343 result
344 Calendar::SetTimeZone(const TimeZone& timeZone)
345 {
346         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
347         return _pCalendarImpl->SetTimeZoneImpl(timeZone);
348 }
349
350 result
351 Calendar::GetTimeInMillisec(long long& millisec) const
352 {
353         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
354         return _pCalendarImpl->GetTimeInMillisecImpl(millisec);
355 }
356
357 result
358 Calendar::SetTimeInMillisec(long long millisec)
359 {
360         SysAssertf(_pCalendarImpl != null, "Not yet constructed! Construct() should be called before use.");
361         return _pCalendarImpl->SetTimeInMillisecImpl(millisec);
362 }
363
364 bool
365 Calendar::IsEquivalentTo(const Calendar& calendar) const
366 {
367         bool isEquivalent = ((_isLenient == calendar.IsLenient()) &&
368                                                  (GetFirstDayOfWeek() == calendar.GetFirstDayOfWeek()) &&
369                                                  (GetMinDaysInFirstWeek() == calendar.GetMinDaysInFirstWeek()) &&
370                                                  (_timeZone == calendar.GetTimeZone()));
371         return isEquivalent;
372 }
373
374 };
375 };      // Tizen::Locales