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.
17 * @file FScl_CalendarbookUtil.cpp
18 * @brief This is the implementation for _CalendarbookUtil class.
20 * This file contains definitions of @e _CalendarbookUtil class.
25 #include <unique_ptr.h>
26 #include <FBaseResult.h>
27 #include <FBaseDateTime.h>
28 #include <FBaseColIList.h>
29 #include <FBaseUtilStringUtil.h>
30 #include <FLclTimeZone.h>
31 #include <FLclGregorianCalendar.h>
32 #include <FSclReminder.h>
33 #include <FBaseSysLog.h>
34 #include <FBase_StringConverter.h>
35 #include <FApp_AppInfo.h>
36 #include "FScl_CalendarbookImpl.h"
37 #include "FScl_CalendarbookUtil.h"
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Utility;
41 using namespace Tizen::Base::Collection;
43 namespace Tizen { namespace Social
46 static const byte _CALENDARBOOK_BYTE_VALUE_9 = 0x09;
47 static const int CALENDARBOOK_DEC_ASCII_MASK = 0x30;
48 static const int CALENDARBOOK_CHAR_ASCII_DIFF = 55;
50 static const int _CALENDARBOOK_MSEC_UNIT = 1000;
51 static const long long _CALENDARBOOK_EPOCH_YEAR_INTERVAL_SECONDS = 62135596800;
53 static const wchar_t* _EVENT_CATEGORY_DELIMITER = L",";
54 static const wchar_t* _EVENT_CATEGORY_APPOINTMENT_STRING = L"Appointment";
55 static const wchar_t* _EVENT_CATEGORY_ANNIVERSARY_STRING = L"Anniversary";
57 static const wchar_t _CALENDARBOOK_UTC_SUFFIX = L'Z';
58 static const wchar_t _CALENDARBOOK_TIME_PREFIX = L'T';
59 static const wchar_t* _CALENDARBOOK_UTC_TZID = L"TZID=";
60 static const wchar_t _CALENDARBOOK_DATE_TIME_DELIMITER = L':';
61 static const int _CALENDARBOOK_TZID_INDEX = 5;
62 static const int _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH = 16; // ex :20120629T193000Z
63 static const int _CALENDARBOOK_DATE_VALUE_STRING_LENGTH = 8; // ex :20120629
64 static const int _CALENDARBOOK_TIME_VALUE_STRING_LENGTH = 6; // ex :193000
65 static const int _CALENDARBOOK_DATE_YEAR_STRING_LENGTH = 4;
66 static const int _CALENDARBOOK_DATE_MONTH_STRING_LENGTH = 2;
67 static const int _CALENDARBOOK_DATE_DAY_STRING_LENGTH = 2;
68 static const int _CALENDARBOOK_TIME_HOUR_STRING_LENGTH = 2;
69 static const int _CALENDARBOOK_TIME_MINUTE_STRING_LENGTH = 2;
70 static const int _CALENDARBOOK_TIME_SECOND_STRING_LENGTH = 2;
71 static const wchar_t* _CALENDARBOOK_ZERO_STRING = L"0";
74 _CalendarbookUtil::ConvertDateTimeToEpochTime(const DateTime& dateTime)
76 return (dateTime.GetTime().GetTicks() / _CALENDARBOOK_MSEC_UNIT) - _CALENDARBOOK_EPOCH_YEAR_INTERVAL_SECONDS;
80 _CalendarbookUtil::ConvertEpochTimeToDateTime(long long int dateTime)
83 tmpDateTime.SetValue(TimeSpan((dateTime + _CALENDARBOOK_EPOCH_YEAR_INTERVAL_SECONDS) * _CALENDARBOOK_MSEC_UNIT));
88 _CalendarbookUtil::ConvertByteBufferToCharArrayN(const ByteBuffer& byteBuffer)
90 int byteBufferLength = byteBuffer.GetCapacity();
91 char* pCharArray = new (std::nothrow) char[byteBufferLength * 2 + 1];
92 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
94 const byte* pByteBufferPtr = byteBuffer.GetPointer();
98 for (int i = 0; i < byteBufferLength; i++)
100 tmpByte = pByteBufferPtr[i] >> 4;
102 if (tmpByte <= _CALENDARBOOK_BYTE_VALUE_9)
104 pCharArray[i * 2] = tmpByte | CALENDARBOOK_DEC_ASCII_MASK;
108 pCharArray[i * 2] = tmpByte + CALENDARBOOK_CHAR_ASCII_DIFF;
111 tmpByte = pByteBufferPtr[i] & 0x0F;
113 if (tmpByte <= _CALENDARBOOK_BYTE_VALUE_9)
115 pCharArray[i * 2 + 1] = tmpByte | CALENDARBOOK_DEC_ASCII_MASK;
119 pCharArray[i * 2 + 1] = tmpByte + CALENDARBOOK_CHAR_ASCII_DIFF;
123 pCharArray[byteBufferLength * 2] = 0;
129 _CalendarbookUtil::ConvertCharArrayToByteBufferN(const char* pCharArray)
131 int charArrayLength = strlen(pCharArray);
132 SysTryReturn(NID_SCL, charArrayLength > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
134 int byteBufferLength = 0;
135 std::unique_ptr<byte[]> pByteArray(new (std::nothrow) byte[charArrayLength/2]);
136 SysTryReturn(NID_SCL, pByteArray != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
138 bool inProgress = false;
142 for (int i = 0; i < charArrayLength; i++)
144 tmpChar = pCharArray[i];
146 if (tmpChar >= '0' && tmpChar <= '9')
150 else if (tmpChar >= 'A' && tmpChar <= 'F')
152 tmpChar -= CALENDARBOOK_CHAR_ASCII_DIFF;
161 tmpByte = tmpChar << 4;
166 pByteArray[byteBufferLength] = tmpByte | tmpChar;
173 result r = E_SUCCESS;
174 std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer());
175 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
176 r = pByteBuffer->Construct(byteBufferLength);
177 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
178 r = pByteBuffer->SetArray(pByteArray.get(), 0, byteBufferLength);
179 pByteBuffer->Rewind();
181 return pByteBuffer.release();
185 _CalendarbookUtil::ConvertEventAlarmsToReminderList(calendar_record_h calendarRecordHandle, ArrayList& reminderList)
187 int errorCode = CALENDAR_ERROR_NONE;
189 unsigned int reminderCount = 0;
190 errorCode = calendar_record_get_child_record_count(calendarRecordHandle, _calendar_event.calendar_alarm, &reminderCount);
192 if (reminderCount == 0)
194 reminderList.RemoveAll(true);
198 for (int i = 0; i< reminderCount; i++)
200 calendar_record_h tmpAlarmHandle = null;
201 int tmpAlarmTickUnit = CALENDAR_ALARM_NONE;
202 int tmpAlarmTick = 0;
203 long long tmpAlarmTime = 0;
204 char* pTmpAlarmTone = null;
206 errorCode = calendar_record_get_child_record_at_p(calendarRecordHandle, _calendar_event.calendar_alarm, i, &tmpAlarmHandle);
207 errorCode = calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick_unit, &tmpAlarmTickUnit);
208 errorCode = calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick, &tmpAlarmTick);
209 errorCode = calendar_record_get_lli(tmpAlarmHandle, _calendar_alarm.time, &tmpAlarmTime);
210 errorCode = calendar_record_get_str_p(tmpAlarmHandle, _calendar_alarm.tone, &pTmpAlarmTone);
212 std::unique_ptr<Reminder> pReminder(new (std::nothrow) Reminder());
213 SysTryReturnResult(NID_SCL, pReminder != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
215 pReminder->SetSoundFile(pTmpAlarmTone);
217 switch (tmpAlarmTickUnit)
219 case CALENDAR_ALARM_TIME_UNIT_MINUTE:
220 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_MINUTE, tmpAlarmTick);
222 case CALENDAR_ALARM_TIME_UNIT_HOUR:
223 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_HOUR, tmpAlarmTick);
225 case CALENDAR_ALARM_TIME_UNIT_DAY:
226 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick);
228 case CALENDAR_ALARM_TIME_UNIT_WEEK:
229 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_WEEK, tmpAlarmTick);
231 case CALENDAR_ALARM_TIME_UNIT_MONTH:
233 calendar_time_s startCalendarTime;
234 DateTime tmpStartTime;
236 errorCode = calendar_record_get_caltime(calendarRecordHandle, _calendar_event.start_time, &startCalendarTime);
237 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
239 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
243 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
246 tmpStartTime.AddMonths(-1);
247 int maxDays = GetMaxDaysOfMonth(tmpStartTime.GetYear(), tmpStartTime.GetMonth());
249 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick * maxDays);
252 case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
253 if (Tizen::App::_AppInfo::GetApiVersion() > _API_VERSION_2_0)
255 pReminder->SetAbsoluteTime(_CalendarbookUtil::ConvertEpochTimeToDateTime(tmpAlarmTime));
262 reminderList.Add(*pReminder.release());
269 _CalendarbookUtil::ConvertTodoAlarmsToReminderList(calendar_record_h calendarRecordHandle, ArrayList& reminderList)
271 int errorCode = CALENDAR_ERROR_NONE;
273 unsigned int reminderCount = 0;
274 errorCode = calendar_record_get_child_record_count(calendarRecordHandle, _calendar_todo.calendar_alarm, &reminderCount);
276 if (reminderCount == 0)
278 reminderList.RemoveAll(true);
282 for (int i = 0; i< reminderCount; i++)
284 calendar_record_h tmpAlarmHandle = null;
285 int tmpAlarmTickUnit = CALENDAR_ALARM_NONE;
286 int tmpAlarmTick = 0;
287 long long tmpAlarmTime = 0;
288 char* pTmpAlarmTone = null;
290 errorCode = calendar_record_get_child_record_at_p(calendarRecordHandle, _calendar_todo.calendar_alarm, i, &tmpAlarmHandle);
291 errorCode = calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick_unit, &tmpAlarmTickUnit);
292 errorCode = calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick, &tmpAlarmTick);
293 errorCode = calendar_record_get_lli(tmpAlarmHandle, _calendar_alarm.time, &tmpAlarmTime);
294 errorCode = calendar_record_get_str_p(tmpAlarmHandle, _calendar_alarm.tone, &pTmpAlarmTone);
296 std::unique_ptr<Reminder> pReminder(new (std::nothrow) Reminder());
297 SysTryReturnResult(NID_SCL, pReminder != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
299 pReminder->SetSoundFile(pTmpAlarmTone);
301 switch (tmpAlarmTickUnit)
303 case CALENDAR_ALARM_TIME_UNIT_MINUTE:
304 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_MINUTE, tmpAlarmTick);
306 case CALENDAR_ALARM_TIME_UNIT_HOUR:
307 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_HOUR, tmpAlarmTick);
309 case CALENDAR_ALARM_TIME_UNIT_DAY:
310 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick);
312 case CALENDAR_ALARM_TIME_UNIT_WEEK:
313 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_WEEK, tmpAlarmTick);
315 case CALENDAR_ALARM_TIME_UNIT_MONTH:
317 calendar_time_s startCalendarTime;
318 DateTime tmpStartTime;
320 errorCode = calendar_record_get_caltime(calendarRecordHandle, _calendar_todo.start_time, &startCalendarTime);
321 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
323 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
327 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
330 tmpStartTime.AddMonths(-1);
331 int maxDays = GetMaxDaysOfMonth(tmpStartTime.GetYear(), tmpStartTime.GetMonth());
333 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick * maxDays);
336 case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
337 if (Tizen::App::_AppInfo::GetApiVersion() > _API_VERSION_2_0)
339 pReminder->SetAbsoluteTime(_CalendarbookUtil::ConvertEpochTimeToDateTime(tmpAlarmTime));
346 reminderList.Add(*pReminder.release());
353 _CalendarbookUtil::ConvertDateTimeToCalTime(const DateTime& dateTime, calendar_time_s& convertedCalTime)
355 convertedCalTime.type = CALENDAR_TIME_UTIME;
356 convertedCalTime.time.utime = ConvertDateTimeToEpochTime(dateTime);
360 _CalendarbookUtil::ConvertDateToCalTime(const DateTime& dateTime, calendar_time_s& convertedCalTime)
362 convertedCalTime.type = CALENDAR_TIME_LOCALTIME;
363 convertedCalTime.time.date.year = dateTime.GetYear();
364 convertedCalTime.time.date.month = dateTime.GetMonth();
365 convertedCalTime.time.date.mday = dateTime.GetDay();
369 _CalendarbookUtil::ConvertRRuleDateTimeStringToDateTime(const String& dateTimeString, DateTime& dateTime, Tizen::Locales::TimeZone& timeZone, bool& isDate)
371 result r = E_SUCCESS;
375 // Split the dateTimeString into date value, time value and time zone
376 if (dateTimeString.GetLength() == _CALENDARBOOK_DATE_VALUE_STRING_LENGTH)
378 dateValue = dateTimeString;
381 else if (dateTimeString.GetLength() == _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH)
383 int timeValueIndex = 0;
385 r = dateTimeString.LastIndexOf(_CALENDARBOOK_TIME_PREFIX, _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1, timeValueIndex);
386 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no T prefix
387 SysTryReturnResult(NID_SCL, timeValueIndex == _CALENDARBOOK_DATE_VALUE_STRING_LENGTH
388 , E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of T is wrong
390 r = dateTimeString.LastIndexOf(_CALENDARBOOK_UTC_SUFFIX, _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1, suffixIndex);
391 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no Z suffix
392 SysTryReturnResult(NID_SCL, suffixIndex == _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1
393 , E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of Z is wrong
395 r = dateTimeString.SubString(0, _CALENDARBOOK_DATE_VALUE_STRING_LENGTH, dateValue);
396 r = dateTimeString.SubString(_CALENDARBOOK_DATE_VALUE_STRING_LENGTH + 1
397 , _CALENDARBOOK_TIME_VALUE_STRING_LENGTH, timeValue);
400 else if (dateTimeString.GetLength() > _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH) // including timezone ID
403 int dateValueIndex = 0;
405 r = dateTimeString.LastIndexOf(_CALENDARBOOK_UTC_TZID, dateTimeString.GetLength() - 1, dateValueIndex);
406 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no TZID
407 SysTryReturnResult(NID_SCL, dateValueIndex == 0, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of TZID is wrong
409 r = dateTimeString.LastIndexOf(_CALENDARBOOK_DATE_TIME_DELIMITER, dateTimeString.GetLength() - 1, dateValueIndex);
410 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no TZID
412 r = dateTimeString.SubString(_CALENDARBOOK_TZID_INDEX, dateValueIndex - _CALENDARBOOK_TZID_INDEX, timeZoneId);
413 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
417 r = dateTimeString.SubString(dateValueIndex, _CALENDARBOOK_DATE_VALUE_STRING_LENGTH, dateValue);
418 r = dateTimeString.SubString(dateValueIndex +_CALENDARBOOK_DATE_VALUE_STRING_LENGTH + 1
419 , _CALENDARBOOK_TIME_VALUE_STRING_LENGTH, timeValue);
421 r = Tizen::Locales::TimeZone::GetTimeZone(timeZoneId, timeZone);
422 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // not supported timezone ID
427 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. date time string = %S", dateTimeString.GetPointer());
428 return E_INVALID_ARG;
441 r = dateValue.SubString(tmpIndex, _CALENDARBOOK_DATE_YEAR_STRING_LENGTH, tmpString);
442 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
443 r = Integer::Parse(tmpString, yearValue);
444 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
445 tmpIndex += _CALENDARBOOK_DATE_YEAR_STRING_LENGTH;
447 r = dateValue.SubString(tmpIndex, _CALENDARBOOK_DATE_MONTH_STRING_LENGTH, tmpString);
448 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
449 r = Integer::Parse(tmpString, monthValue);
450 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
451 tmpIndex += _CALENDARBOOK_DATE_MONTH_STRING_LENGTH;
453 r = dateValue.SubString(tmpIndex, _CALENDARBOOK_DATE_DAY_STRING_LENGTH, tmpString);
454 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
455 r = Integer::Parse(tmpString, dayValue);
456 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
457 tmpIndex += _CALENDARBOOK_DATE_DAY_STRING_LENGTH;
463 r = timeValue.SubString(tmpIndex, _CALENDARBOOK_TIME_HOUR_STRING_LENGTH, tmpString);
464 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
465 r = Integer::Parse(tmpString, hourValue);
466 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
467 tmpIndex += _CALENDARBOOK_TIME_HOUR_STRING_LENGTH;
469 r = timeValue.SubString(tmpIndex, _CALENDARBOOK_TIME_MINUTE_STRING_LENGTH, tmpString);
470 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
471 r = Integer::Parse(tmpString, minuteValue);
472 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
473 tmpIndex += _CALENDARBOOK_TIME_MINUTE_STRING_LENGTH;
475 r = timeValue.SubString(tmpIndex, _CALENDARBOOK_TIME_SECOND_STRING_LENGTH, tmpString);
476 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
477 r = Integer::Parse(tmpString, secondValue);
478 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
479 tmpIndex += _CALENDARBOOK_TIME_SECOND_STRING_LENGTH;
482 r = dateTime.SetValue(yearValue, monthValue, dayValue, hourValue, minuteValue, secondValue);
483 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
489 _CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(const Tizen::Base::DateTime& dateTime, bool isDate)
491 result r = E_SUCCESS;
494 r = exdateString.Append(dateTime.GetYear());
496 if (dateTime.GetMonth() < 10)
498 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
500 r = exdateString.Append(dateTime.GetMonth());
502 if (dateTime.GetDay() < 10)
504 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
506 r = exdateString.Append(dateTime.GetDay());
510 r = exdateString.Append(_CALENDARBOOK_TIME_PREFIX);
512 if (dateTime.GetHour() < 10)
514 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
516 r = exdateString.Append(dateTime.GetHour());
518 if (dateTime.GetMinute() < 10)
520 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
522 r = exdateString.Append(dateTime.GetMinute());
524 if (dateTime.GetSecond() < 10)
526 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
528 r = exdateString.Append(dateTime.GetSecond());
530 r = exdateString.Append(_CALENDARBOOK_UTC_SUFFIX);
536 calendar_event_status_e
537 _CalendarbookUtil::ConvertEventStatusToCSEventStatus(int status)
539 calendar_event_status_e convertedEventStatus = CALENDAR_EVENT_STATUS_NONE;
543 case EVENT_STATUS_NONE:
544 convertedEventStatus = CALENDAR_EVENT_STATUS_NONE;
546 case EVENT_STATUS_TENTATIVE:
547 convertedEventStatus = CALENDAR_EVENT_STATUS_TENTATIVE;
549 case EVENT_STATUS_CONFIRMED:
550 convertedEventStatus = CALENDAR_EVENT_STATUS_CONFIRMED;
552 case EVENT_STATUS_CANCELLED:
553 convertedEventStatus = CALENDAR_EVENT_STATUS_CANCELLED;
556 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", status);
557 convertedEventStatus = CALENDAR_EVENT_STATUS_NONE;
561 return convertedEventStatus;
564 calendar_event_busy_status_e
565 _CalendarbookUtil::ConvertBusyStatusToCSEventBusyStatus(int busyStatus)
567 calendar_event_busy_status_e convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
571 case BUSY_STATUS_FREE:
572 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
574 case BUSY_STATUS_BUSY:
575 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_BUSY;
577 case BUSY_STATUS_UNAVAILABLE:
578 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE;
580 case BUSY_STATUS_TENTATIVE:
581 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_TENTATIVE;
584 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. busyStatus = %d", busyStatus);
585 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
589 return convertedBusyStatus;
592 calendar_event_priority_e
593 _CalendarbookUtil::ConvertEventPriorityToCSEventPriority(int priority)
595 calendar_event_priority_e convertedPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
599 case EVENT_PRIORITY_LOW:
600 convertedPriority = CALENDAR_EVENT_PRIORITY_LOW;
602 case EVENT_PRIORITY_NORMAL:
603 convertedPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
605 case EVENT_PRIORITY_HIGH:
606 convertedPriority = CALENDAR_EVENT_PRIORITY_HIGH;
609 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", priority);
610 convertedPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
614 return convertedPriority;
617 calendar_sensitivity_e
618 _CalendarbookUtil::ConvertSensitivityToCSSensitivity(int sensitivity)
620 calendar_sensitivity_e convertedSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
624 case SENSITIVITY_PUBLIC:
625 convertedSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
627 case SENSITIVITY_PRIVATE:
628 convertedSensitivity = CALENDAR_SENSITIVITY_PRIVATE;
630 case SENSITIVITY_CONFIDENTIAL:
631 convertedSensitivity = CALENDAR_SENSITIVITY_CONFIDENTIAL;
634 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. sensitivity = %d", sensitivity);
635 convertedSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
639 return convertedSensitivity;
642 calendar_todo_status_e
643 _CalendarbookUtil::ConvertTodoStatusToCSTodoStatus(int status)
645 calendar_todo_status_e convertedTodoStatus = CALENDAR_TODO_STATUS_NONE;
649 case TODO_STATUS_NONE:
650 convertedTodoStatus = CALENDAR_TODO_STATUS_NONE;
652 case TODO_STATUS_NEEDS_ACTION:
653 convertedTodoStatus = CALENDAR_TODO_STATUS_NEEDS_ACTION;
655 case TODO_STATUS_COMPLETED:
656 convertedTodoStatus = CALENDAR_TODO_STATUS_COMPLETED;
658 case TODO_STATUS_IN_PROCESS:
659 convertedTodoStatus = CALENDAR_TODO_STATUS_IN_PROCESS;
661 case TODO_STATUS_CANCELLED:
662 convertedTodoStatus = CALENDAR_TODO_STATUS_CANCELED;
665 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", status);
666 convertedTodoStatus = CALENDAR_TODO_STATUS_NONE;
670 return convertedTodoStatus;
673 calendar_todo_priority_e
674 _CalendarbookUtil::ConvertTodoPriorityToCSTodoPriority(int priority)
676 calendar_todo_priority_e convertedPriority = CALENDAR_TODO_PRIORITY_NONE;
680 case TODO_PRIORITY_LOW:
681 convertedPriority = CALENDAR_TODO_PRIORITY_LOW;
683 case TODO_PRIORITY_NORMAL:
684 convertedPriority = CALENDAR_TODO_PRIORITY_NORMAL;
686 case TODO_PRIORITY_HIGH:
687 convertedPriority = CALENDAR_TODO_PRIORITY_HIGH;
690 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", priority);
691 convertedPriority = CALENDAR_TODO_PRIORITY_NONE;
695 return convertedPriority;
699 _CalendarbookUtil::ConvertCalendarItemTypeToCSCalendarbookType(int itemType)
701 int storeType = CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO;
705 case CALENDAR_ITEM_TYPE_EVENT_ONLY:
706 storeType = CALENDAR_BOOK_TYPE_EVENT;
708 case CALENDAR_ITEM_TYPE_TODO_ONLY:
709 storeType = CALENDAR_BOOK_TYPE_TODO;
711 case CALENDAR_ITEM_TYPE_EVENT_AND_TODO:
712 storeType = CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO;
715 storeType = CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO;
723 _CalendarbookUtil::ConvertCSCategoriesToEventCategory(const char* pCategories)
725 result r = E_SUCCESS;
727 EventCategory eventCategory = EVENT_CATEGORY_APPOINTMENT;
728 String tmpString(pCategories);
729 String delim(_EVENT_CATEGORY_DELIMITER);
732 StringTokenizer strTok(tmpString, delim);
733 while (strTok.HasMoreTokens())
735 r = strTok.GetNextToken(token);
736 SysTryReturn(NID_SCL, r == E_SUCCESS, EVENT_CATEGORY_APPOINTMENT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
737 if (token == _EVENT_CATEGORY_APPOINTMENT_STRING)
739 eventCategory = EVENT_CATEGORY_APPOINTMENT;
742 else if (token == _EVENT_CATEGORY_ANNIVERSARY_STRING)
744 eventCategory = EVENT_CATEGORY_ANNIVERSARY;
749 return eventCategory;
753 _CalendarbookUtil::GetMaxDaysOfMonth(int year, int month)
755 int maxDaysOfMonth = 0;
756 Tizen::Locales::Calendar* pGregorianCalendar = Tizen::Locales::Calendar::CreateInstanceN(Tizen::Locales::CALENDAR_GREGORIAN);
758 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_YEAR, year);
759 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_MONTH, month);
761 maxDaysOfMonth = pGregorianCalendar->GetActualMaxTimeField(Tizen::Locales::TIME_FIELD_DAY_OF_MONTH);
763 delete pGregorianCalendar;
765 return maxDaysOfMonth;
769 _CalendarbookUtil::CheckValidDateTime(const DateTime& dateTime)
771 if (dateTime < _CalendarbookImpl::GetMinDateTime() || dateTime > _CalendarbookImpl::GetMaxDateTime())