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 unsigned int reminderCount = 0;
188 calendar_record_get_child_record_count(calendarRecordHandle, _calendar_event.calendar_alarm, &reminderCount);
190 if (reminderCount == 0)
192 reminderList.RemoveAll(true);
196 for (unsigned int i = 0; i< reminderCount; i++)
198 calendar_record_h tmpAlarmHandle = null;
199 int tmpAlarmTickUnit = CALENDAR_ALARM_NONE;
200 int tmpAlarmTick = 0;
201 long long tmpAlarmTime = 0;
202 char* pTmpAlarmTone = null;
204 calendar_record_get_child_record_at_p(calendarRecordHandle, _calendar_event.calendar_alarm, i, &tmpAlarmHandle);
205 calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick_unit, &tmpAlarmTickUnit);
206 calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick, &tmpAlarmTick);
207 calendar_record_get_lli(tmpAlarmHandle, _calendar_alarm.time, &tmpAlarmTime);
208 calendar_record_get_str_p(tmpAlarmHandle, _calendar_alarm.tone, &pTmpAlarmTone);
210 std::unique_ptr<Reminder> pReminder(new (std::nothrow) Reminder());
211 SysTryReturnResult(NID_SCL, pReminder != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
213 pReminder->SetSoundFile(pTmpAlarmTone);
215 switch (tmpAlarmTickUnit)
217 case CALENDAR_ALARM_TIME_UNIT_MINUTE:
218 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_MINUTE, tmpAlarmTick);
220 case CALENDAR_ALARM_TIME_UNIT_HOUR:
221 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_HOUR, tmpAlarmTick);
223 case CALENDAR_ALARM_TIME_UNIT_DAY:
224 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick);
226 case CALENDAR_ALARM_TIME_UNIT_WEEK:
227 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_WEEK, tmpAlarmTick);
229 case CALENDAR_ALARM_TIME_UNIT_MONTH:
231 calendar_time_s startCalendarTime;
232 DateTime tmpStartTime;
234 calendar_record_get_caltime(calendarRecordHandle, _calendar_event.start_time, &startCalendarTime);
235 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
237 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
241 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
244 tmpStartTime.AddMonths(-1);
245 int maxDays = GetMaxDaysOfMonth(tmpStartTime.GetYear(), tmpStartTime.GetMonth());
247 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick * maxDays);
250 case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
251 if (Tizen::App::_AppInfo::GetApiVersion() > _API_VERSION_2_0)
253 pReminder->SetAbsoluteTime(_CalendarbookUtil::ConvertEpochTimeToDateTime(tmpAlarmTime));
260 reminderList.Add(*pReminder.release());
267 _CalendarbookUtil::ConvertTodoAlarmsToReminderList(calendar_record_h calendarRecordHandle, ArrayList& reminderList)
269 unsigned int reminderCount = 0;
270 calendar_record_get_child_record_count(calendarRecordHandle, _calendar_todo.calendar_alarm, &reminderCount);
272 if (reminderCount == 0)
274 reminderList.RemoveAll(true);
278 for (unsigned int i = 0; i< reminderCount; i++)
280 calendar_record_h tmpAlarmHandle = null;
281 int tmpAlarmTickUnit = CALENDAR_ALARM_NONE;
282 int tmpAlarmTick = 0;
283 long long tmpAlarmTime = 0;
284 char* pTmpAlarmTone = null;
286 calendar_record_get_child_record_at_p(calendarRecordHandle, _calendar_todo.calendar_alarm, i, &tmpAlarmHandle);
287 calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick_unit, &tmpAlarmTickUnit);
288 calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick, &tmpAlarmTick);
289 calendar_record_get_lli(tmpAlarmHandle, _calendar_alarm.time, &tmpAlarmTime);
290 calendar_record_get_str_p(tmpAlarmHandle, _calendar_alarm.tone, &pTmpAlarmTone);
292 std::unique_ptr<Reminder> pReminder(new (std::nothrow) Reminder());
293 SysTryReturnResult(NID_SCL, pReminder != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
295 pReminder->SetSoundFile(pTmpAlarmTone);
297 switch (tmpAlarmTickUnit)
299 case CALENDAR_ALARM_TIME_UNIT_MINUTE:
300 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_MINUTE, tmpAlarmTick);
302 case CALENDAR_ALARM_TIME_UNIT_HOUR:
303 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_HOUR, tmpAlarmTick);
305 case CALENDAR_ALARM_TIME_UNIT_DAY:
306 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick);
308 case CALENDAR_ALARM_TIME_UNIT_WEEK:
309 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_WEEK, tmpAlarmTick);
311 case CALENDAR_ALARM_TIME_UNIT_MONTH:
313 calendar_time_s startCalendarTime;
314 DateTime tmpStartTime;
316 calendar_record_get_caltime(calendarRecordHandle, _calendar_todo.start_time, &startCalendarTime);
317 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
319 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
323 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
326 tmpStartTime.AddMonths(-1);
327 int maxDays = GetMaxDaysOfMonth(tmpStartTime.GetYear(), tmpStartTime.GetMonth());
329 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick * maxDays);
332 case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
333 if (Tizen::App::_AppInfo::GetApiVersion() > _API_VERSION_2_0)
335 pReminder->SetAbsoluteTime(_CalendarbookUtil::ConvertEpochTimeToDateTime(tmpAlarmTime));
342 reminderList.Add(*pReminder.release());
349 _CalendarbookUtil::ConvertDateTimeToCalTime(const DateTime& dateTime, calendar_time_s& convertedCalTime)
351 convertedCalTime.type = CALENDAR_TIME_UTIME;
352 convertedCalTime.time.utime = ConvertDateTimeToEpochTime(dateTime);
356 _CalendarbookUtil::ConvertDateToCalTime(const DateTime& dateTime, calendar_time_s& convertedCalTime)
358 convertedCalTime.type = CALENDAR_TIME_LOCALTIME;
359 convertedCalTime.time.date.year = dateTime.GetYear();
360 convertedCalTime.time.date.month = dateTime.GetMonth();
361 convertedCalTime.time.date.mday = dateTime.GetDay();
365 _CalendarbookUtil::ConvertRRuleDateTimeStringToDateTime(const String& dateTimeString, DateTime& dateTime, Tizen::Locales::TimeZone& timeZone, bool& isDate)
367 result r = E_SUCCESS;
371 // Split the dateTimeString into date value, time value and time zone
372 if (dateTimeString.GetLength() == _CALENDARBOOK_DATE_VALUE_STRING_LENGTH)
374 dateValue = dateTimeString;
377 else if (dateTimeString.GetLength() == _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH)
379 int timeValueIndex = 0;
381 r = dateTimeString.LastIndexOf(_CALENDARBOOK_TIME_PREFIX, _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1, timeValueIndex);
382 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no T prefix
383 SysTryReturnResult(NID_SCL, timeValueIndex == _CALENDARBOOK_DATE_VALUE_STRING_LENGTH
384 , E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of T is wrong
386 r = dateTimeString.LastIndexOf(_CALENDARBOOK_UTC_SUFFIX, _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1, suffixIndex);
387 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no Z suffix
388 SysTryReturnResult(NID_SCL, suffixIndex == _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1
389 , E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of Z is wrong
391 r = dateTimeString.SubString(0, _CALENDARBOOK_DATE_VALUE_STRING_LENGTH, dateValue);
392 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
393 r = dateTimeString.SubString(_CALENDARBOOK_DATE_VALUE_STRING_LENGTH + 1
394 , _CALENDARBOOK_TIME_VALUE_STRING_LENGTH, timeValue);
395 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
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 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
418 r = dateTimeString.SubString(dateValueIndex +_CALENDARBOOK_DATE_VALUE_STRING_LENGTH + 1
419 , _CALENDARBOOK_TIME_VALUE_STRING_LENGTH, timeValue);
420 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
422 r = Tizen::Locales::TimeZone::GetTimeZone(timeZoneId, timeZone);
423 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // not supported timezone ID
428 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. date time string = %S", dateTimeString.GetPointer());
429 return E_INVALID_ARG;
442 r = dateValue.SubString(tmpIndex, _CALENDARBOOK_DATE_YEAR_STRING_LENGTH, tmpString);
443 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
444 r = Integer::Parse(tmpString, yearValue);
445 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
446 tmpIndex += _CALENDARBOOK_DATE_YEAR_STRING_LENGTH;
448 r = dateValue.SubString(tmpIndex, _CALENDARBOOK_DATE_MONTH_STRING_LENGTH, tmpString);
449 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
450 r = Integer::Parse(tmpString, monthValue);
451 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
452 tmpIndex += _CALENDARBOOK_DATE_MONTH_STRING_LENGTH;
454 r = dateValue.SubString(tmpIndex, _CALENDARBOOK_DATE_DAY_STRING_LENGTH, tmpString);
455 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
456 r = Integer::Parse(tmpString, dayValue);
457 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
458 tmpIndex += _CALENDARBOOK_DATE_DAY_STRING_LENGTH;
464 r = timeValue.SubString(tmpIndex, _CALENDARBOOK_TIME_HOUR_STRING_LENGTH, tmpString);
465 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
466 r = Integer::Parse(tmpString, hourValue);
467 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
468 tmpIndex += _CALENDARBOOK_TIME_HOUR_STRING_LENGTH;
470 r = timeValue.SubString(tmpIndex, _CALENDARBOOK_TIME_MINUTE_STRING_LENGTH, tmpString);
471 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
472 r = Integer::Parse(tmpString, minuteValue);
473 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
474 tmpIndex += _CALENDARBOOK_TIME_MINUTE_STRING_LENGTH;
476 r = timeValue.SubString(tmpIndex, _CALENDARBOOK_TIME_SECOND_STRING_LENGTH, tmpString);
477 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
478 r = Integer::Parse(tmpString, secondValue);
479 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
480 tmpIndex += _CALENDARBOOK_TIME_SECOND_STRING_LENGTH;
483 r = dateTime.SetValue(yearValue, monthValue, dayValue, hourValue, minuteValue, secondValue);
484 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
490 _CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(const Tizen::Base::DateTime& dateTime, bool isDate)
494 exdateString.Append(dateTime.GetYear());
496 if (dateTime.GetMonth() < 10)
498 exdateString.Append(_CALENDARBOOK_ZERO_STRING);
500 exdateString.Append(dateTime.GetMonth());
502 if (dateTime.GetDay() < 10)
504 exdateString.Append(_CALENDARBOOK_ZERO_STRING);
506 exdateString.Append(dateTime.GetDay());
510 exdateString.Append(_CALENDARBOOK_TIME_PREFIX);
512 if (dateTime.GetHour() < 10)
514 exdateString.Append(_CALENDARBOOK_ZERO_STRING);
516 exdateString.Append(dateTime.GetHour());
518 if (dateTime.GetMinute() < 10)
520 exdateString.Append(_CALENDARBOOK_ZERO_STRING);
522 exdateString.Append(dateTime.GetMinute());
524 if (dateTime.GetSecond() < 10)
526 exdateString.Append(_CALENDARBOOK_ZERO_STRING);
528 exdateString.Append(dateTime.GetSecond());
530 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())