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(byteBufferLength);
178 SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
179 r = pByteBuffer->SetArray(pByteArray.get(), 0, byteBufferLength);
180 pByteBuffer->Rewind();
182 return pByteBuffer.release();
186 _CalendarbookUtil::ConvertEventAlarmsToReminderList(calendar_record_h calendarRecordHandle, ArrayList& reminderList)
188 int errorCode = CALENDAR_ERROR_NONE;
190 unsigned int reminderCount = 0;
191 errorCode = calendar_record_get_child_record_count(calendarRecordHandle, _calendar_event.calendar_alarm, &reminderCount);
193 if (reminderCount == 0)
195 reminderList.RemoveAll(true);
199 for (int i = 0; i< reminderCount; i++)
201 calendar_record_h tmpAlarmHandle = null;
202 int tmpAlarmTickUnit = CALENDAR_ALARM_NONE;
203 int tmpAlarmTick = 0;
204 long long tmpAlarmTime = 0;
205 char* pTmpAlarmTone = null;
207 errorCode = calendar_record_get_child_record_at_p(calendarRecordHandle, _calendar_event.calendar_alarm, i, &tmpAlarmHandle);
208 errorCode = calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick_unit, &tmpAlarmTickUnit);
209 errorCode = calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick, &tmpAlarmTick);
210 errorCode = calendar_record_get_lli(tmpAlarmHandle, _calendar_alarm.time, &tmpAlarmTime);
211 errorCode = calendar_record_get_str_p(tmpAlarmHandle, _calendar_alarm.tone, &pTmpAlarmTone);
213 std::unique_ptr<Reminder> pReminder(new (std::nothrow) Reminder());
214 SysTryReturnResult(NID_SCL, pReminder != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
216 pReminder->SetSoundFile(pTmpAlarmTone);
218 switch (tmpAlarmTickUnit)
220 case CALENDAR_ALARM_TIME_UNIT_MINUTE:
221 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_MINUTE, tmpAlarmTick);
223 case CALENDAR_ALARM_TIME_UNIT_HOUR:
224 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_HOUR, tmpAlarmTick);
226 case CALENDAR_ALARM_TIME_UNIT_DAY:
227 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick);
229 case CALENDAR_ALARM_TIME_UNIT_WEEK:
230 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_WEEK, tmpAlarmTick);
232 case CALENDAR_ALARM_TIME_UNIT_MONTH:
234 calendar_time_s startCalendarTime;
235 DateTime tmpStartTime;
237 errorCode = calendar_record_get_caltime(calendarRecordHandle, _calendar_event.start_time, &startCalendarTime);
238 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
240 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
244 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
247 tmpStartTime.AddMonths(-1);
248 int maxDays = GetMaxDaysOfMonth(tmpStartTime.GetYear(), tmpStartTime.GetMonth());
250 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick * maxDays);
253 case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
254 if (Tizen::App::_AppInfo::GetApiVersion() > _API_VERSION_2_0)
256 pReminder->SetAbsoluteTime(_CalendarbookUtil::ConvertEpochTimeToDateTime(tmpAlarmTime));
263 reminderList.Add(*pReminder.release());
270 _CalendarbookUtil::ConvertTodoAlarmsToReminderList(calendar_record_h calendarRecordHandle, ArrayList& reminderList)
272 int errorCode = CALENDAR_ERROR_NONE;
274 unsigned int reminderCount = 0;
275 errorCode = calendar_record_get_child_record_count(calendarRecordHandle, _calendar_todo.calendar_alarm, &reminderCount);
277 if (reminderCount == 0)
279 reminderList.RemoveAll(true);
283 for (int i = 0; i< reminderCount; i++)
285 calendar_record_h tmpAlarmHandle = null;
286 int tmpAlarmTickUnit = CALENDAR_ALARM_NONE;
287 int tmpAlarmTick = 0;
288 long long tmpAlarmTime = 0;
289 char* pTmpAlarmTone = null;
291 errorCode = calendar_record_get_child_record_at_p(calendarRecordHandle, _calendar_todo.calendar_alarm, i, &tmpAlarmHandle);
292 errorCode = calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick_unit, &tmpAlarmTickUnit);
293 errorCode = calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick, &tmpAlarmTick);
294 errorCode = calendar_record_get_lli(tmpAlarmHandle, _calendar_alarm.time, &tmpAlarmTime);
295 errorCode = calendar_record_get_str_p(tmpAlarmHandle, _calendar_alarm.tone, &pTmpAlarmTone);
297 std::unique_ptr<Reminder> pReminder(new (std::nothrow) Reminder());
298 SysTryReturnResult(NID_SCL, pReminder != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
300 pReminder->SetSoundFile(pTmpAlarmTone);
302 switch (tmpAlarmTickUnit)
304 case CALENDAR_ALARM_TIME_UNIT_MINUTE:
305 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_MINUTE, tmpAlarmTick);
307 case CALENDAR_ALARM_TIME_UNIT_HOUR:
308 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_HOUR, tmpAlarmTick);
310 case CALENDAR_ALARM_TIME_UNIT_DAY:
311 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick);
313 case CALENDAR_ALARM_TIME_UNIT_WEEK:
314 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_WEEK, tmpAlarmTick);
316 case CALENDAR_ALARM_TIME_UNIT_MONTH:
318 calendar_time_s startCalendarTime;
319 DateTime tmpStartTime;
321 errorCode = calendar_record_get_caltime(calendarRecordHandle, _calendar_todo.start_time, &startCalendarTime);
322 if (startCalendarTime.type == CALENDAR_TIME_UTIME)
324 tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
328 tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
331 tmpStartTime.AddMonths(-1);
332 int maxDays = GetMaxDaysOfMonth(tmpStartTime.GetYear(), tmpStartTime.GetMonth());
334 pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick * maxDays);
337 case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
338 if (Tizen::App::_AppInfo::GetApiVersion() > _API_VERSION_2_0)
340 pReminder->SetAbsoluteTime(_CalendarbookUtil::ConvertEpochTimeToDateTime(tmpAlarmTime));
347 reminderList.Add(*pReminder.release());
354 _CalendarbookUtil::ConvertDateTimeToCalTime(const DateTime& dateTime, calendar_time_s& convertedCalTime)
356 convertedCalTime.type = CALENDAR_TIME_UTIME;
357 convertedCalTime.time.utime = ConvertDateTimeToEpochTime(dateTime);
361 _CalendarbookUtil::ConvertDateToCalTime(const DateTime& dateTime, calendar_time_s& convertedCalTime)
363 convertedCalTime.type = CALENDAR_TIME_LOCALTIME;
364 convertedCalTime.time.date.year = dateTime.GetYear();
365 convertedCalTime.time.date.month = dateTime.GetMonth();
366 convertedCalTime.time.date.mday = dateTime.GetDay();
370 _CalendarbookUtil::ConvertRRuleDateTimeStringToDateTime(const String& dateTimeString, DateTime& dateTime, Tizen::Locales::TimeZone& timeZone, bool& isDate)
372 result r = E_SUCCESS;
376 // Split the dateTimeString into date value, time value and time zone
377 if (dateTimeString.GetLength() == _CALENDARBOOK_DATE_VALUE_STRING_LENGTH)
379 dateValue = dateTimeString;
382 else if (dateTimeString.GetLength() == _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH)
384 int timeValueIndex = 0;
386 r = dateTimeString.LastIndexOf(_CALENDARBOOK_TIME_PREFIX, _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1, timeValueIndex);
387 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no T prefix
388 SysTryReturnResult(NID_SCL, timeValueIndex == _CALENDARBOOK_DATE_VALUE_STRING_LENGTH
389 , E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of T is wrong
391 r = dateTimeString.LastIndexOf(_CALENDARBOOK_UTC_SUFFIX, _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1, suffixIndex);
392 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no Z suffix
393 SysTryReturnResult(NID_SCL, suffixIndex == _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1
394 , E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of Z is wrong
396 r = dateTimeString.SubString(0, _CALENDARBOOK_DATE_VALUE_STRING_LENGTH, dateValue);
397 r = dateTimeString.SubString(_CALENDARBOOK_DATE_VALUE_STRING_LENGTH + 1
398 , _CALENDARBOOK_TIME_VALUE_STRING_LENGTH, timeValue);
401 else if (dateTimeString.GetLength() > _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH) // including timezone ID
404 int dateValueIndex = 0;
406 r = dateTimeString.LastIndexOf(_CALENDARBOOK_UTC_TZID, dateTimeString.GetLength() - 1, dateValueIndex);
407 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no TZID
408 SysTryReturnResult(NID_SCL, dateValueIndex == 0, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of TZID is wrong
410 r = dateTimeString.LastIndexOf(_CALENDARBOOK_DATE_TIME_DELIMITER, dateTimeString.GetLength() - 1, dateValueIndex);
411 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no TZID
413 r = dateTimeString.SubString(_CALENDARBOOK_TZID_INDEX, dateValueIndex - _CALENDARBOOK_TZID_INDEX, timeZoneId);
414 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, dateValue);
419 r = dateTimeString.SubString(dateValueIndex +_CALENDARBOOK_DATE_VALUE_STRING_LENGTH + 1
420 , _CALENDARBOOK_TIME_VALUE_STRING_LENGTH, timeValue);
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)
492 result r = E_SUCCESS;
495 r = exdateString.Append(dateTime.GetYear());
497 if (dateTime.GetMonth() < 10)
499 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
501 r = exdateString.Append(dateTime.GetMonth());
503 if (dateTime.GetDay() < 10)
505 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
507 r = exdateString.Append(dateTime.GetDay());
511 r = exdateString.Append(_CALENDARBOOK_TIME_PREFIX);
513 if (dateTime.GetHour() < 10)
515 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
517 r = exdateString.Append(dateTime.GetHour());
519 if (dateTime.GetMinute() < 10)
521 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
523 r = exdateString.Append(dateTime.GetMinute());
525 if (dateTime.GetSecond() < 10)
527 r = exdateString.Append(_CALENDARBOOK_ZERO_STRING);
529 r = exdateString.Append(dateTime.GetSecond());
531 r = exdateString.Append(_CALENDARBOOK_UTC_SUFFIX);
537 calendar_event_status_e
538 _CalendarbookUtil::ConvertEventStatusToCSEventStatus(int status)
540 calendar_event_status_e convertedEventStatus = CALENDAR_EVENT_STATUS_NONE;
544 case EVENT_STATUS_NONE:
545 convertedEventStatus = CALENDAR_EVENT_STATUS_NONE;
547 case EVENT_STATUS_TENTATIVE:
548 convertedEventStatus = CALENDAR_EVENT_STATUS_TENTATIVE;
550 case EVENT_STATUS_CONFIRMED:
551 convertedEventStatus = CALENDAR_EVENT_STATUS_CONFIRMED;
553 case EVENT_STATUS_CANCELLED:
554 convertedEventStatus = CALENDAR_EVENT_STATUS_CANCELLED;
557 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", status);
558 convertedEventStatus = CALENDAR_EVENT_STATUS_NONE;
562 return convertedEventStatus;
565 calendar_event_busy_status_e
566 _CalendarbookUtil::ConvertBusyStatusToCSEventBusyStatus(int busyStatus)
568 calendar_event_busy_status_e convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
572 case BUSY_STATUS_FREE:
573 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
575 case BUSY_STATUS_BUSY:
576 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_BUSY;
578 case BUSY_STATUS_UNAVAILABLE:
579 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE;
581 case BUSY_STATUS_TENTATIVE:
582 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_TENTATIVE;
585 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. busyStatus = %d", busyStatus);
586 convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
590 return convertedBusyStatus;
593 calendar_event_priority_e
594 _CalendarbookUtil::ConvertEventPriorityToCSEventPriority(int priority)
596 calendar_event_priority_e convertedPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
600 case EVENT_PRIORITY_LOW:
601 convertedPriority = CALENDAR_EVENT_PRIORITY_LOW;
603 case EVENT_PRIORITY_NORMAL:
604 convertedPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
606 case EVENT_PRIORITY_HIGH:
607 convertedPriority = CALENDAR_EVENT_PRIORITY_HIGH;
610 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", priority);
611 convertedPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
615 return convertedPriority;
618 calendar_sensitivity_e
619 _CalendarbookUtil::ConvertSensitivityToCSSensitivity(int sensitivity)
621 calendar_sensitivity_e convertedSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
625 case SENSITIVITY_PUBLIC:
626 convertedSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
628 case SENSITIVITY_PRIVATE:
629 convertedSensitivity = CALENDAR_SENSITIVITY_PRIVATE;
631 case SENSITIVITY_CONFIDENTIAL:
632 convertedSensitivity = CALENDAR_SENSITIVITY_CONFIDENTIAL;
635 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. sensitivity = %d", sensitivity);
636 convertedSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
640 return convertedSensitivity;
643 calendar_todo_status_e
644 _CalendarbookUtil::ConvertTodoStatusToCSTodoStatus(int status)
646 calendar_todo_status_e convertedTodoStatus = CALENDAR_TODO_STATUS_NONE;
650 case TODO_STATUS_NONE:
651 convertedTodoStatus = CALENDAR_TODO_STATUS_NONE;
653 case TODO_STATUS_NEEDS_ACTION:
654 convertedTodoStatus = CALENDAR_TODO_STATUS_NEEDS_ACTION;
656 case TODO_STATUS_COMPLETED:
657 convertedTodoStatus = CALENDAR_TODO_STATUS_COMPLETED;
659 case TODO_STATUS_IN_PROCESS:
660 convertedTodoStatus = CALENDAR_TODO_STATUS_IN_PROCESS;
662 case TODO_STATUS_CANCELLED:
663 convertedTodoStatus = CALENDAR_TODO_STATUS_CANCELED;
666 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", status);
667 convertedTodoStatus = CALENDAR_TODO_STATUS_NONE;
671 return convertedTodoStatus;
674 calendar_todo_priority_e
675 _CalendarbookUtil::ConvertTodoPriorityToCSTodoPriority(int priority)
677 calendar_todo_priority_e convertedPriority = CALENDAR_TODO_PRIORITY_NONE;
681 case TODO_PRIORITY_LOW:
682 convertedPriority = CALENDAR_TODO_PRIORITY_LOW;
684 case TODO_PRIORITY_NORMAL:
685 convertedPriority = CALENDAR_TODO_PRIORITY_NORMAL;
687 case TODO_PRIORITY_HIGH:
688 convertedPriority = CALENDAR_TODO_PRIORITY_HIGH;
691 SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", priority);
692 convertedPriority = CALENDAR_TODO_PRIORITY_NONE;
696 return convertedPriority;
700 _CalendarbookUtil::ConvertCalendarItemTypeToCSCalendarbookType(int itemType)
702 int storeType = CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO;
706 case CALENDAR_ITEM_TYPE_EVENT_ONLY:
707 storeType = CALENDAR_BOOK_TYPE_EVENT;
709 case CALENDAR_ITEM_TYPE_TODO_ONLY:
710 storeType = CALENDAR_BOOK_TYPE_TODO;
712 case CALENDAR_ITEM_TYPE_EVENT_AND_TODO:
713 storeType = CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO;
716 storeType = CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO;
724 _CalendarbookUtil::ConvertCSCategoriesToEventCategory(const char* pCategories)
726 result r = E_SUCCESS;
728 EventCategory eventCategory = EVENT_CATEGORY_APPOINTMENT;
729 String tmpString(pCategories);
730 String delim(_EVENT_CATEGORY_DELIMITER);
733 StringTokenizer strTok(tmpString, delim);
734 while (strTok.HasMoreTokens())
736 r = strTok.GetNextToken(token);
737 SysTryReturn(NID_SCL, r == E_SUCCESS, EVENT_CATEGORY_APPOINTMENT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
738 if (token == _EVENT_CATEGORY_APPOINTMENT_STRING)
740 eventCategory = EVENT_CATEGORY_APPOINTMENT;
743 else if (token == _EVENT_CATEGORY_ANNIVERSARY_STRING)
745 eventCategory = EVENT_CATEGORY_ANNIVERSARY;
750 return eventCategory;
754 _CalendarbookUtil::GetMaxDaysOfMonth(int year, int month)
756 int maxDaysOfMonth = 0;
757 Tizen::Locales::Calendar* pGregorianCalendar = Tizen::Locales::Calendar::CreateInstanceN(Tizen::Locales::CALENDAR_GREGORIAN);
759 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_YEAR, year);
760 pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_MONTH, month);
762 maxDaysOfMonth = pGregorianCalendar->GetActualMaxTimeField(Tizen::Locales::TIME_FIELD_DAY_OF_MONTH);
764 delete pGregorianCalendar;
766 return maxDaysOfMonth;
770 _CalendarbookUtil::CheckValidDateTime(const DateTime& dateTime)
772 if (dateTime < _CalendarbookImpl::GetMinDateTime() || dateTime > _CalendarbookImpl::GetMaxDateTime())