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.
18 * @file FScl_CalendarbookUtil.cpp
19 * @brief This is the implementation for _CalendarbookUtil class.
21 * This file contains definitions of @e _CalendarbookUtil class.
26 #include <unique_ptr.h>
27 #include <FBaseResult.h>
28 #include <FBaseDateTime.h>
29 #include <FBaseColIList.h>
30 #include <FBaseUtilStringUtil.h>
31 #include <FLclTimeZone.h>
32 #include <FLclGregorianCalendar.h>
33 #include <FSclReminder.h>
34 #include <FBaseSysLog.h>
35 #include <FBase_StringConverter.h>
36 #include <FApp_AppInfo.h>
37 #include "FScl_CalendarbookImpl.h"
38 #include "FScl_CalendarbookUtil.h"
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Utility;
42 using namespace Tizen::Base::Collection;
44 namespace Tizen { namespace Social
47 static const byte _CALENDARBOOK_BYTE_VALUE_9 = 0x09;
48 static const int CALENDARBOOK_DEC_ASCII_MASK = 0x30;
49 static const int CALENDARBOOK_CHAR_ASCII_DIFF = 55;
51 static const int _CALENDARBOOK_MSEC_UNIT = 1000;
52 static const long long _CALENDARBOOK_EPOCH_YEAR_INTERVAL_SECONDS = 62135596800;
54 static const wchar_t* _EVENT_CATEGORY_DELIMITER = L",";
55 static const wchar_t* _EVENT_CATEGORY_APPOINTMENT_STRING = L"Appointment";
56 static const wchar_t* _EVENT_CATEGORY_ANNIVERSARY_STRING = L"Anniversary";
58 static const wchar_t _CALENDARBOOK_UTC_SUFFIX = L'Z';
59 static const wchar_t _CALENDARBOOK_TIME_PREFIX = L'T';
60 static const wchar_t* _CALENDARBOOK_UTC_TZID = L"TZID=";
61 static const wchar_t _CALENDARBOOK_DATE_TIME_DELIMITER = L':';
62 static const int _CALENDARBOOK_TZID_INDEX = 5;
63 static const int _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH = 16; // ex :20120629T193000Z
64 static const int _CALENDARBOOK_DATE_VALUE_STRING_LENGTH = 8; // ex :20120629
65 static const int _CALENDARBOOK_TIME_VALUE_STRING_LENGTH = 6; // ex :193000
66 static const int _CALENDARBOOK_DATE_YEAR_STRING_LENGTH = 4;
67 static const int _CALENDARBOOK_DATE_MONTH_STRING_LENGTH = 2;
68 static const int _CALENDARBOOK_DATE_DAY_STRING_LENGTH = 2;
69 static const int _CALENDARBOOK_TIME_HOUR_STRING_LENGTH = 2;
70 static const int _CALENDARBOOK_TIME_MINUTE_STRING_LENGTH = 2;
71 static const int _CALENDARBOOK_TIME_SECOND_STRING_LENGTH = 2;
72 static const wchar_t* _CALENDARBOOK_ZERO_STRING = L"0";
75 _CalendarbookUtil::ConvertDateTimeToEpochTime(const DateTime& dateTime)
77 return (dateTime.GetTime().GetTicks() / _CALENDARBOOK_MSEC_UNIT) - _CALENDARBOOK_EPOCH_YEAR_INTERVAL_SECONDS;
81 _CalendarbookUtil::ConvertEpochTimeToDateTime(long long int dateTime)
84 tmpDateTime.SetValue(TimeSpan((dateTime + _CALENDARBOOK_EPOCH_YEAR_INTERVAL_SECONDS) * _CALENDARBOOK_MSEC_UNIT));
89 _CalendarbookUtil::ConvertByteBufferToCharArrayN(const ByteBuffer& byteBuffer)
91 int byteBufferLength = byteBuffer.GetCapacity();
92 char* pCharArray = new (std::nothrow) char[byteBufferLength * 2 + 1];
93 SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
95 const byte* pByteBufferPtr = byteBuffer.GetPointer();
99 for (int i = 0; i < byteBufferLength; i++)
101 tmpByte = pByteBufferPtr[i] >> 4;
103 if (tmpByte <= _CALENDARBOOK_BYTE_VALUE_9)
105 pCharArray[i * 2] = tmpByte | CALENDARBOOK_DEC_ASCII_MASK;
109 pCharArray[i * 2] = tmpByte + CALENDARBOOK_CHAR_ASCII_DIFF;
112 tmpByte = pByteBufferPtr[i] & 0x0F;
114 if (tmpByte <= _CALENDARBOOK_BYTE_VALUE_9)
116 pCharArray[i * 2 + 1] = tmpByte | CALENDARBOOK_DEC_ASCII_MASK;
120 pCharArray[i * 2 + 1] = tmpByte + CALENDARBOOK_CHAR_ASCII_DIFF;
124 pCharArray[byteBufferLength * 2] = 0;
130 _CalendarbookUtil::ConvertCharArrayToByteBufferN(const char* pCharArray)
132 int charArrayLength = strlen(pCharArray);
133 SysTryReturn(NID_SCL, charArrayLength > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
135 int byteBufferLength = 0;
136 std::unique_ptr<byte[]> pByteArray(new (std::nothrow) byte[charArrayLength/2]);
137 SysTryReturn(NID_SCL, pByteArray != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
139 bool inProgress = false;
143 for (int i = 0; i < charArrayLength; i++)
145 tmpChar = pCharArray[i];
147 if (tmpChar >= '0' && tmpChar <= '9')
151 else if (tmpChar >= 'A' && tmpChar <= 'F')
153 tmpChar -= CALENDARBOOK_CHAR_ASCII_DIFF;
162 tmpByte = tmpChar << 4;
167 pByteArray[byteBufferLength] = tmpByte | tmpChar;
174 result r = E_SUCCESS;
175 std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer());
176 SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
177 r = pByteBuffer->Construct(pByteArray.release(), 0, byteBufferLength, byteBufferLength);
178 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
180 return pByteBuffer.release();
184 _CalendarbookUtil::ConvertEventAlarmsToReminderList(calendar_record_h calendarRecordHandle, ArrayList& reminderList)
186 int errorCode = CALENDAR_ERROR_NONE;
188 unsigned int reminderCount = 0;
189 errorCode = calendar_record_get_child_record_count(calendarRecordHandle, _calendar_event.calendar_alarm, &reminderCount);
191 if (reminderCount == 0)
193 reminderList.RemoveAll(true);
197 for (int i = 0; i< reminderCount; i++)
199 calendar_record_h tmpAlarmHandle = null;
200 int tmpAlarmTickUnit = CALENDAR_ALARM_NONE;
201 int tmpAlarmTick = 0;
202 long long tmpAlarmTime = 0;
203 char* pTmpAlarmTone = null;
205 errorCode = calendar_record_get_child_record_at_p(calendarRecordHandle, _calendar_event.calendar_alarm, i, &tmpAlarmHandle);
206 errorCode = calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick_unit, &tmpAlarmTickUnit);
207 errorCode = calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick, &tmpAlarmTick);
208 errorCode = calendar_record_get_lli(tmpAlarmHandle, _calendar_alarm.time, &tmpAlarmTime);
209 errorCode = calendar_record_get_str_p(tmpAlarmHandle, _calendar_alarm.tone, &pTmpAlarmTone);
211 std::unique_ptr<Reminder> pReminder(new (std::nothrow) Reminder());
212 SysTryReturnResult(NID_SCL, pReminder != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
214 pReminder->SetSoundFile(pTmpAlarmTone);
216 switch (tmpAlarmTickUnit)
218 case CALENDAR_ALARM_TIME_UNIT_MINUTE:
219 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_MINUTE, tmpAlarmTick);
221 case CALENDAR_ALARM_TIME_UNIT_HOUR:
222 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_HOUR, tmpAlarmTick);
224 case CALENDAR_ALARM_TIME_UNIT_DAY:
225 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick);
227 case CALENDAR_ALARM_TIME_UNIT_WEEK:
228 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_WEEK, tmpAlarmTick);
230 case CALENDAR_ALARM_TIME_UNIT_MONTH:
232 calendar_time_s startCalendarTime;
233 DateTime tmpStartTime;
235 errorCode = calendar_record_get_caltime(calendarRecordHandle, _calendar_event.start_time, &startCalendarTime);
236 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
238 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
242 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
245 tmpStartTime.AddMonths(-1);
246 int maxDays = GetMaxDaysOfMonth(tmpStartTime.GetYear(), tmpStartTime.GetMonth());
248 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick * maxDays);
251 case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
252 if (Tizen::App::_AppInfo::GetApiVersion() > _API_VERSION_2_0)
254 pReminder->SetAbsoluteTime(_CalendarbookUtil::ConvertEpochTimeToDateTime(tmpAlarmTime));
261 reminderList.Add(*pReminder.release());
268 _CalendarbookUtil::ConvertTodoAlarmsToReminderList(calendar_record_h calendarRecordHandle, ArrayList& reminderList)
270 int errorCode = CALENDAR_ERROR_NONE;
272 unsigned int reminderCount = 0;
273 errorCode = calendar_record_get_child_record_count(calendarRecordHandle, _calendar_todo.calendar_alarm, &reminderCount);
275 if (reminderCount == 0)
277 reminderList.RemoveAll(true);
281 for (int i = 0; i< reminderCount; i++)
283 calendar_record_h tmpAlarmHandle = null;
284 int tmpAlarmTickUnit = CALENDAR_ALARM_NONE;
285 int tmpAlarmTick = 0;
286 long long tmpAlarmTime = 0;
287 char* pTmpAlarmTone = null;
289 errorCode = calendar_record_get_child_record_at_p(calendarRecordHandle, _calendar_todo.calendar_alarm, i, &tmpAlarmHandle);
290 errorCode = calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick_unit, &tmpAlarmTickUnit);
291 errorCode = calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick, &tmpAlarmTick);
292 errorCode = calendar_record_get_lli(tmpAlarmHandle, _calendar_alarm.time, &tmpAlarmTime);
293 errorCode = calendar_record_get_str_p(tmpAlarmHandle, _calendar_alarm.tone, &pTmpAlarmTone);
295 std::unique_ptr<Reminder> pReminder(new (std::nothrow) Reminder());
296 SysTryReturnResult(NID_SCL, pReminder != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
298 pReminder->SetSoundFile(pTmpAlarmTone);
300 switch (tmpAlarmTickUnit)
302 case CALENDAR_ALARM_TIME_UNIT_MINUTE:
303 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_MINUTE, tmpAlarmTick);
305 case CALENDAR_ALARM_TIME_UNIT_HOUR:
306 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_HOUR, tmpAlarmTick);
308 case CALENDAR_ALARM_TIME_UNIT_DAY:
309 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick);
311 case CALENDAR_ALARM_TIME_UNIT_WEEK:
312 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_WEEK, tmpAlarmTick);
314 case CALENDAR_ALARM_TIME_UNIT_MONTH:
316 calendar_time_s startCalendarTime;
317 DateTime tmpStartTime;
319 errorCode = calendar_record_get_caltime(calendarRecordHandle, _calendar_todo.start_time, &startCalendarTime);
320 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
322 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
326 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
329 tmpStartTime.AddMonths(-1);
330 int maxDays = GetMaxDaysOfMonth(tmpStartTime.GetYear(), tmpStartTime.GetMonth());
332 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick * maxDays);
335 case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
336 if (Tizen::App::_AppInfo::GetApiVersion() > _API_VERSION_2_0)
338 pReminder->SetAbsoluteTime(_CalendarbookUtil::ConvertEpochTimeToDateTime(tmpAlarmTime));
345 reminderList.Add(*pReminder.release());
352 _CalendarbookUtil::ConvertDateTimeToCalTime(const DateTime& dateTime, calendar_time_s& convertedCalTime)
354 convertedCalTime.type = CALENDAR_TIME_UTIME;
355 convertedCalTime.time.utime = ConvertDateTimeToEpochTime(dateTime);
359 _CalendarbookUtil::ConvertDateToCalTime(const DateTime& dateTime, calendar_time_s& convertedCalTime)
361 convertedCalTime.type = CALENDAR_TIME_LOCALTIME;
362 convertedCalTime.time.date.year = dateTime.GetYear();
363 convertedCalTime.time.date.month = dateTime.GetMonth();
364 convertedCalTime.time.date.mday = dateTime.GetDay();
368 _CalendarbookUtil::ConvertRRuleDateTimeStringToDateTime(const String& dateTimeString, DateTime& dateTime, Tizen::Locales::TimeZone& timeZone, bool& isDate)
370 result r = E_SUCCESS;
374 // Split the dateTimeString into date value, time value and time zone
375 if (dateTimeString.GetLength() == _CALENDARBOOK_DATE_VALUE_STRING_LENGTH)
377 dateValue = dateTimeString;
380 else if (dateTimeString.GetLength() == _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH)
382 int timeValueIndex = 0;
384 r = dateTimeString.LastIndexOf(_CALENDARBOOK_TIME_PREFIX, _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1, timeValueIndex);
385 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no T prefix
386 SysTryReturnResult(NID_SCL, timeValueIndex == _CALENDARBOOK_DATE_VALUE_STRING_LENGTH
387 , E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of T is wrong
389 r = dateTimeString.LastIndexOf(_CALENDARBOOK_UTC_SUFFIX, _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1, suffixIndex);
390 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no Z suffix
391 SysTryReturnResult(NID_SCL, suffixIndex == _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1
392 , E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of Z is wrong
394 r = dateTimeString.SubString(0, _CALENDARBOOK_DATE_VALUE_STRING_LENGTH, dateValue);
395 r = dateTimeString.SubString(_CALENDARBOOK_DATE_VALUE_STRING_LENGTH + 1
396 , _CALENDARBOOK_TIME_VALUE_STRING_LENGTH, timeValue);
399 else if (dateTimeString.GetLength() > _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH) // including timezone ID
402 int dateValueIndex = 0;
404 r = dateTimeString.LastIndexOf(_CALENDARBOOK_UTC_TZID, dateTimeString.GetLength() - 1, dateValueIndex);
405 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no TZID
406 SysTryReturnResult(NID_SCL, dateValueIndex == 0, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of TZID is wrong
408 r = dateTimeString.LastIndexOf(_CALENDARBOOK_DATE_TIME_DELIMITER, dateTimeString.GetLength() - 1, dateValueIndex);
409 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no TZID
411 r = dateTimeString.SubString(_CALENDARBOOK_TZID_INDEX, dateValueIndex - _CALENDARBOOK_TZID_INDEX, timeZoneId);
412 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
416 r = dateTimeString.SubString(dateValueIndex, _CALENDARBOOK_DATE_VALUE_STRING_LENGTH, dateValue);
417 r = dateTimeString.SubString(dateValueIndex +_CALENDARBOOK_DATE_VALUE_STRING_LENGTH + 1
418 , _CALENDARBOOK_TIME_VALUE_STRING_LENGTH, timeValue);
420 r = Tizen::Locales::TimeZone::GetTimeZone(timeZoneId, timeZone);
421 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // not supported timezone ID
426 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. date time string = %S", dateTimeString.GetPointer());
427 return E_INVALID_ARG;
440 r = dateValue.SubString(tmpIndex, _CALENDARBOOK_DATE_YEAR_STRING_LENGTH, tmpString);
441 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
442 r = Integer::Parse(tmpString, yearValue);
443 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
444 tmpIndex += _CALENDARBOOK_DATE_YEAR_STRING_LENGTH;
446 r = dateValue.SubString(tmpIndex, _CALENDARBOOK_DATE_MONTH_STRING_LENGTH, tmpString);
447 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
448 r = Integer::Parse(tmpString, monthValue);
449 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
450 tmpIndex += _CALENDARBOOK_DATE_MONTH_STRING_LENGTH;
452 r = dateValue.SubString(tmpIndex, _CALENDARBOOK_DATE_DAY_STRING_LENGTH, tmpString);
453 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
454 r = Integer::Parse(tmpString, dayValue);
455 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
456 tmpIndex += _CALENDARBOOK_DATE_DAY_STRING_LENGTH;
462 r = timeValue.SubString(tmpIndex, _CALENDARBOOK_TIME_HOUR_STRING_LENGTH, tmpString);
463 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
464 r = Integer::Parse(tmpString, hourValue);
465 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
466 tmpIndex += _CALENDARBOOK_TIME_HOUR_STRING_LENGTH;
468 r = timeValue.SubString(tmpIndex, _CALENDARBOOK_TIME_MINUTE_STRING_LENGTH, tmpString);
469 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
470 r = Integer::Parse(tmpString, minuteValue);
471 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
472 tmpIndex += _CALENDARBOOK_TIME_MINUTE_STRING_LENGTH;
474 r = timeValue.SubString(tmpIndex, _CALENDARBOOK_TIME_SECOND_STRING_LENGTH, tmpString);
475 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
476 r = Integer::Parse(tmpString, secondValue);
477 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
478 tmpIndex += _CALENDARBOOK_TIME_SECOND_STRING_LENGTH;
481 r = dateTime.SetValue(yearValue, monthValue, dayValue, hourValue, minuteValue, secondValue);
482 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
488 _CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(const Tizen::Base::DateTime& dateTime, bool isDate)
490 result r = E_SUCCESS;
493 r = exdateString.Append(dateTime.GetYear());
495 if (dateTime.GetMonth() < 10)
497 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
499 r = exdateString.Append(dateTime.GetMonth());
501 if (dateTime.GetDay() < 10)
503 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
505 r = exdateString.Append(dateTime.GetDay());
509 r = exdateString.Append(_CALENDARBOOK_TIME_PREFIX);
511 if (dateTime.GetHour() < 10)
513 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
515 r = exdateString.Append(dateTime.GetHour());
517 if (dateTime.GetMinute() < 10)
519 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
521 r = exdateString.Append(dateTime.GetMinute());
523 if (dateTime.GetSecond() < 10)
525 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
527 r = exdateString.Append(dateTime.GetSecond());
529 r = exdateString.Append(_CALENDARBOOK_UTC_SUFFIX);
535 calendar_event_status_e
536 _CalendarbookUtil::ConvertEventStatusToCSEventStatus(int status)
538 calendar_event_status_e convertedEventStatus = CALENDAR_EVENT_STATUS_NONE;
542 case EVENT_STATUS_NONE:
543 convertedEventStatus = CALENDAR_EVENT_STATUS_NONE;
545 case EVENT_STATUS_TENTATIVE:
546 convertedEventStatus = CALENDAR_EVENT_STATUS_TENTATIVE;
548 case EVENT_STATUS_CONFIRMED:
549 convertedEventStatus = CALENDAR_EVENT_STATUS_CONFIRMED;
551 case EVENT_STATUS_CANCELLED:
552 convertedEventStatus = CALENDAR_EVENT_STATUS_CANCELLED;
555 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", status);
556 convertedEventStatus = CALENDAR_EVENT_STATUS_NONE;
560 return convertedEventStatus;
563 calendar_event_busy_status_e
564 _CalendarbookUtil::ConvertBusyStatusToCSEventBusyStatus(int busyStatus)
566 calendar_event_busy_status_e convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
570 case BUSY_STATUS_FREE:
571 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
573 case BUSY_STATUS_BUSY:
574 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_BUSY;
576 case BUSY_STATUS_UNAVAILABLE:
577 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE;
579 case BUSY_STATUS_TENTATIVE:
580 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_TENTATIVE;
583 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. busyStatus = %d", busyStatus);
584 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
588 return convertedBusyStatus;
591 calendar_event_priority_e
592 _CalendarbookUtil::ConvertEventPriorityToCSEventPriority(int priority)
594 calendar_event_priority_e convertedPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
598 case EVENT_PRIORITY_LOW:
599 convertedPriority = CALENDAR_EVENT_PRIORITY_LOW;
601 case EVENT_PRIORITY_NORMAL:
602 convertedPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
604 case EVENT_PRIORITY_HIGH:
605 convertedPriority = CALENDAR_EVENT_PRIORITY_HIGH;
608 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", priority);
609 convertedPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
613 return convertedPriority;
616 calendar_sensitivity_e
617 _CalendarbookUtil::ConvertSensitivityToCSSensitivity(int sensitivity)
619 calendar_sensitivity_e convertedSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
623 case SENSITIVITY_PUBLIC:
624 convertedSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
626 case SENSITIVITY_PRIVATE:
627 convertedSensitivity = CALENDAR_SENSITIVITY_PRIVATE;
629 case SENSITIVITY_CONFIDENTIAL:
630 convertedSensitivity = CALENDAR_SENSITIVITY_CONFIDENTIAL;
633 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. sensitivity = %d", sensitivity);
634 convertedSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
638 return convertedSensitivity;
641 calendar_todo_status_e
642 _CalendarbookUtil::ConvertTodoStatusToCSTodoStatus(int status)
644 calendar_todo_status_e convertedTodoStatus = CALENDAR_TODO_STATUS_NONE;
648 case TODO_STATUS_NONE:
649 convertedTodoStatus = CALENDAR_TODO_STATUS_NONE;
651 case TODO_STATUS_NEEDS_ACTION:
652 convertedTodoStatus = CALENDAR_TODO_STATUS_NEEDS_ACTION;
654 case TODO_STATUS_COMPLETED:
655 convertedTodoStatus = CALENDAR_TODO_STATUS_COMPLETED;
657 case TODO_STATUS_IN_PROCESS:
658 convertedTodoStatus = CALENDAR_TODO_STATUS_IN_PROCESS;
660 case TODO_STATUS_CANCELLED:
661 convertedTodoStatus = CALENDAR_TODO_STATUS_CANCELED;
664 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", status);
665 convertedTodoStatus = CALENDAR_TODO_STATUS_NONE;
669 return convertedTodoStatus;
672 calendar_todo_priority_e
673 _CalendarbookUtil::ConvertTodoPriorityToCSTodoPriority(int priority)
675 calendar_todo_priority_e convertedPriority = CALENDAR_TODO_PRIORITY_NONE;
679 case TODO_PRIORITY_LOW:
680 convertedPriority = CALENDAR_TODO_PRIORITY_LOW;
682 case TODO_PRIORITY_NORMAL:
683 convertedPriority = CALENDAR_TODO_PRIORITY_NORMAL;
685 case TODO_PRIORITY_HIGH:
686 convertedPriority = CALENDAR_TODO_PRIORITY_HIGH;
689 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", priority);
690 convertedPriority = CALENDAR_TODO_PRIORITY_NONE;
694 return convertedPriority;
698 _CalendarbookUtil::ConvertCalendarItemTypeToCSCalendarbookType(int itemType)
700 int storeType = CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO;
704 case CALENDAR_ITEM_TYPE_EVENT_ONLY:
705 storeType = CALENDAR_BOOK_TYPE_EVENT;
707 case CALENDAR_ITEM_TYPE_TODO_ONLY:
708 storeType = CALENDAR_BOOK_TYPE_TODO;
710 case CALENDAR_ITEM_TYPE_EVENT_AND_TODO:
711 storeType = CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO;
714 storeType = CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO;
722 _CalendarbookUtil::ConvertCSCategoriesToEventCategory(const char* pCategories)
724 result r = E_SUCCESS;
726 EventCategory eventCategory = EVENT_CATEGORY_APPOINTMENT;
727 String tmpString(pCategories);
728 String delim(_EVENT_CATEGORY_DELIMITER);
731 StringTokenizer strTok(tmpString, delim);
732 while (strTok.HasMoreTokens())
734 r = strTok.GetNextToken(token);
735 SysTryReturn(NID_SCL, r == E_SUCCESS, EVENT_CATEGORY_APPOINTMENT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
736 if (token == _EVENT_CATEGORY_APPOINTMENT_STRING)
738 eventCategory = EVENT_CATEGORY_APPOINTMENT;
741 else if (token == _EVENT_CATEGORY_ANNIVERSARY_STRING)
743 eventCategory = EVENT_CATEGORY_ANNIVERSARY;
748 return eventCategory;
752 _CalendarbookUtil::GetMaxDaysOfMonth(int year, int month)
754 int maxDaysOfMonth = 0;
755 Tizen::Locales::Calendar* pGregorianCalendar = Tizen::Locales::Calendar::CreateInstanceN(Tizen::Locales::CALENDAR_GREGORIAN);
757 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_YEAR, year);
758 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_MONTH, month);
760 maxDaysOfMonth = pGregorianCalendar->GetActualMaxTimeField(Tizen::Locales::TIME_FIELD_DAY_OF_MONTH);
762 delete pGregorianCalendar;
764 return maxDaysOfMonth;
768 _CalendarbookUtil::CheckValidDateTime(const DateTime& dateTime)
770 if (dateTime < _CalendarbookImpl::GetMinDateTime() || dateTime > _CalendarbookImpl::GetMaxDateTime())