1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
|
//
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
/**
* @file FScl_CalendarbookUtil.cpp
* @brief This is the implementation for _CalendarbookUtil class.
*
* This file contains definitions of @e _CalendarbookUtil class.
*/
#include <new>
#include <string.h>
#include <unique_ptr.h>
#include <FBaseResult.h>
#include <FBaseDateTime.h>
#include <FBaseColIList.h>
#include <FBaseUtilStringUtil.h>
#include <FLclTimeZone.h>
#include <FLclGregorianCalendar.h>
#include <FSclReminder.h>
#include <FBaseSysLog.h>
#include <FBase_StringConverter.h>
#include <FApp_AppInfo.h>
#include "FScl_CalendarbookImpl.h"
#include "FScl_CalendarbookUtil.h"
using namespace Tizen::Base;
using namespace Tizen::Base::Utility;
using namespace Tizen::Base::Collection;
namespace Tizen { namespace Social
{
static const byte _CALENDARBOOK_BYTE_VALUE_9 = 0x09;
static const int CALENDARBOOK_DEC_ASCII_MASK = 0x30;
static const int CALENDARBOOK_CHAR_ASCII_DIFF = 55;
static const int _CALENDARBOOK_MSEC_UNIT = 1000;
static const long long _CALENDARBOOK_EPOCH_YEAR_INTERVAL_SECONDS = 62135596800;
static const wchar_t* _EVENT_CATEGORY_DELIMITER = L",";
static const wchar_t* _EVENT_CATEGORY_APPOINTMENT_STRING = L"Appointment";
static const wchar_t* _EVENT_CATEGORY_ANNIVERSARY_STRING = L"Anniversary";
static const wchar_t _CALENDARBOOK_UTC_SUFFIX = L'Z';
static const wchar_t _CALENDARBOOK_TIME_PREFIX = L'T';
static const wchar_t* _CALENDARBOOK_UTC_TZID = L"TZID=";
static const wchar_t _CALENDARBOOK_DATE_TIME_DELIMITER = L':';
static const int _CALENDARBOOK_TZID_INDEX = 5;
static const int _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH = 16; // ex :20120629T193000Z
static const int _CALENDARBOOK_DATE_VALUE_STRING_LENGTH = 8; // ex :20120629
static const int _CALENDARBOOK_TIME_VALUE_STRING_LENGTH = 6; // ex :193000
static const int _CALENDARBOOK_DATE_YEAR_STRING_LENGTH = 4;
static const int _CALENDARBOOK_DATE_MONTH_STRING_LENGTH = 2;
static const int _CALENDARBOOK_DATE_DAY_STRING_LENGTH = 2;
static const int _CALENDARBOOK_TIME_HOUR_STRING_LENGTH = 2;
static const int _CALENDARBOOK_TIME_MINUTE_STRING_LENGTH = 2;
static const int _CALENDARBOOK_TIME_SECOND_STRING_LENGTH = 2;
static const wchar_t* _CALENDARBOOK_ZERO_STRING = L"0";
long long int
_CalendarbookUtil::ConvertDateTimeToEpochTime(const DateTime& dateTime)
{
return (dateTime.GetTime().GetTicks() / _CALENDARBOOK_MSEC_UNIT) - _CALENDARBOOK_EPOCH_YEAR_INTERVAL_SECONDS;
}
DateTime
_CalendarbookUtil::ConvertEpochTimeToDateTime(long long int dateTime)
{
DateTime tmpDateTime;
tmpDateTime.SetValue(TimeSpan((dateTime + _CALENDARBOOK_EPOCH_YEAR_INTERVAL_SECONDS) * _CALENDARBOOK_MSEC_UNIT));
return tmpDateTime;
}
char*
_CalendarbookUtil::ConvertByteBufferToCharArrayN(const ByteBuffer& byteBuffer)
{
int byteBufferLength = byteBuffer.GetCapacity();
char* pCharArray = new (std::nothrow) char[byteBufferLength * 2 + 1];
SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
const byte* pByteBufferPtr = byteBuffer.GetPointer();
byte tmpByte = 0;
for (int i = 0; i < byteBufferLength; i++)
{
tmpByte = pByteBufferPtr[i] >> 4;
if (tmpByte <= _CALENDARBOOK_BYTE_VALUE_9)
{
pCharArray[i * 2] = tmpByte | CALENDARBOOK_DEC_ASCII_MASK;
}
else
{
pCharArray[i * 2] = tmpByte + CALENDARBOOK_CHAR_ASCII_DIFF;
}
tmpByte = pByteBufferPtr[i] & 0x0F;
if (tmpByte <= _CALENDARBOOK_BYTE_VALUE_9)
{
pCharArray[i * 2 + 1] = tmpByte | CALENDARBOOK_DEC_ASCII_MASK;
}
else
{
pCharArray[i * 2 + 1] = tmpByte + CALENDARBOOK_CHAR_ASCII_DIFF;
}
}
pCharArray[byteBufferLength * 2] = 0;
return pCharArray;
}
ByteBuffer*
_CalendarbookUtil::ConvertCharArrayToByteBufferN(const char* pCharArray)
{
int charArrayLength = strlen(pCharArray);
SysTryReturn(NID_SCL, charArrayLength > 0, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
int byteBufferLength = 0;
std::unique_ptr<byte[]> pByteArray(new (std::nothrow) byte[charArrayLength/2]);
SysTryReturn(NID_SCL, pByteArray != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
bool inProgress = false;
char tmpChar = 0;
byte tmpByte = 0;
for (int i = 0; i < charArrayLength; i++)
{
tmpChar = pCharArray[i];
if (tmpChar >= '0' && tmpChar <= '9')
{
tmpChar &= 0x0F;
}
else if (tmpChar >= 'A' && tmpChar <= 'F')
{
tmpChar -= CALENDARBOOK_CHAR_ASCII_DIFF;
}
else
{
continue;
}
if (!inProgress)
{
tmpByte = tmpChar << 4;
inProgress = true;
}
else
{
pByteArray[byteBufferLength] = tmpByte | tmpChar;
byteBufferLength++;
tmpByte = 0;
inProgress = false;
}
}
result r = E_SUCCESS;
std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer());
SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
r = pByteBuffer->Construct(byteBufferLength);
SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
r = pByteBuffer->SetArray(pByteArray.get(), 0, byteBufferLength);
pByteBuffer->Rewind();
return pByteBuffer.release();
}
result
_CalendarbookUtil::ConvertEventAlarmsToReminderList(calendar_record_h calendarRecordHandle, ArrayList& reminderList)
{
unsigned int reminderCount = 0;
calendar_record_get_child_record_count(calendarRecordHandle, _calendar_event.calendar_alarm, &reminderCount);
if (reminderCount == 0)
{
reminderList.RemoveAll(true);
return E_SUCCESS;
}
for (unsigned int i = 0; i< reminderCount; i++)
{
calendar_record_h tmpAlarmHandle = null;
int tmpAlarmTickUnit = CALENDAR_ALARM_NONE;
int tmpAlarmTick = 0;
long long tmpAlarmTime = 0;
char* pTmpAlarmTone = null;
calendar_record_get_child_record_at_p(calendarRecordHandle, _calendar_event.calendar_alarm, i, &tmpAlarmHandle);
calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick_unit, &tmpAlarmTickUnit);
calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick, &tmpAlarmTick);
calendar_record_get_lli(tmpAlarmHandle, _calendar_alarm.time, &tmpAlarmTime);
calendar_record_get_str_p(tmpAlarmHandle, _calendar_alarm.tone, &pTmpAlarmTone);
std::unique_ptr<Reminder> pReminder(new (std::nothrow) Reminder());
SysTryReturnResult(NID_SCL, pReminder != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
pReminder->SetSoundFile(pTmpAlarmTone);
switch (tmpAlarmTickUnit)
{
case CALENDAR_ALARM_TIME_UNIT_MINUTE:
pReminder->SetTimeOffset(REMINDER_TIME_UNIT_MINUTE, tmpAlarmTick);
break;
case CALENDAR_ALARM_TIME_UNIT_HOUR:
pReminder->SetTimeOffset(REMINDER_TIME_UNIT_HOUR, tmpAlarmTick);
break;
case CALENDAR_ALARM_TIME_UNIT_DAY:
pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick);
break;
case CALENDAR_ALARM_TIME_UNIT_WEEK:
pReminder->SetTimeOffset(REMINDER_TIME_UNIT_WEEK, tmpAlarmTick);
break;
case CALENDAR_ALARM_TIME_UNIT_MONTH:
{
calendar_time_s startCalendarTime;
DateTime tmpStartTime;
calendar_record_get_caltime(calendarRecordHandle, _calendar_event.start_time, &startCalendarTime);
if (startCalendarTime.type == CALENDAR_TIME_UTIME)
{
tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
}
else
{
tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
}
tmpStartTime.AddMonths(-1);
int maxDays = GetMaxDaysOfMonth(tmpStartTime.GetYear(), tmpStartTime.GetMonth());
pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick * maxDays);
}
break;
case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
if (Tizen::App::_AppInfo::GetApiVersion() > _API_VERSION_2_0)
{
pReminder->SetAbsoluteTime(_CalendarbookUtil::ConvertEpochTimeToDateTime(tmpAlarmTime));
}
break;
default :
break;
}
reminderList.Add(*pReminder.release());
}
return E_SUCCESS;
}
result
_CalendarbookUtil::ConvertTodoAlarmsToReminderList(calendar_record_h calendarRecordHandle, ArrayList& reminderList)
{
unsigned int reminderCount = 0;
calendar_record_get_child_record_count(calendarRecordHandle, _calendar_todo.calendar_alarm, &reminderCount);
if (reminderCount == 0)
{
reminderList.RemoveAll(true);
return E_SUCCESS;
}
for (unsigned int i = 0; i< reminderCount; i++)
{
calendar_record_h tmpAlarmHandle = null;
int tmpAlarmTickUnit = CALENDAR_ALARM_NONE;
int tmpAlarmTick = 0;
long long tmpAlarmTime = 0;
char* pTmpAlarmTone = null;
calendar_record_get_child_record_at_p(calendarRecordHandle, _calendar_todo.calendar_alarm, i, &tmpAlarmHandle);
calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick_unit, &tmpAlarmTickUnit);
calendar_record_get_int(tmpAlarmHandle, _calendar_alarm.tick, &tmpAlarmTick);
calendar_record_get_lli(tmpAlarmHandle, _calendar_alarm.time, &tmpAlarmTime);
calendar_record_get_str_p(tmpAlarmHandle, _calendar_alarm.tone, &pTmpAlarmTone);
std::unique_ptr<Reminder> pReminder(new (std::nothrow) Reminder());
SysTryReturnResult(NID_SCL, pReminder != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
pReminder->SetSoundFile(pTmpAlarmTone);
switch (tmpAlarmTickUnit)
{
case CALENDAR_ALARM_TIME_UNIT_MINUTE:
pReminder->SetTimeOffset(REMINDER_TIME_UNIT_MINUTE, tmpAlarmTick);
break;
case CALENDAR_ALARM_TIME_UNIT_HOUR:
pReminder->SetTimeOffset(REMINDER_TIME_UNIT_HOUR, tmpAlarmTick);
break;
case CALENDAR_ALARM_TIME_UNIT_DAY:
pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick);
break;
case CALENDAR_ALARM_TIME_UNIT_WEEK:
pReminder->SetTimeOffset(REMINDER_TIME_UNIT_WEEK, tmpAlarmTick);
break;
case CALENDAR_ALARM_TIME_UNIT_MONTH:
{
calendar_time_s startCalendarTime;
DateTime tmpStartTime;
calendar_record_get_caltime(calendarRecordHandle, _calendar_todo.start_time, &startCalendarTime);
if (startCalendarTime.type == CALENDAR_TIME_UTIME)
{
tmpStartTime = _CalendarbookUtil::ConvertEpochTimeToDateTime(startCalendarTime.time.utime);
}
else
{
tmpStartTime.SetValue(startCalendarTime.time.date.year, startCalendarTime.time.date.month, startCalendarTime.time.date.mday);
}
tmpStartTime.AddMonths(-1);
int maxDays = GetMaxDaysOfMonth(tmpStartTime.GetYear(), tmpStartTime.GetMonth());
pReminder->SetTimeOffset(REMINDER_TIME_UNIT_DAY, tmpAlarmTick * maxDays);
}
break;
case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
if (Tizen::App::_AppInfo::GetApiVersion() > _API_VERSION_2_0)
{
pReminder->SetAbsoluteTime(_CalendarbookUtil::ConvertEpochTimeToDateTime(tmpAlarmTime));
}
break;
default :
break;
}
reminderList.Add(*pReminder.release());
}
return E_SUCCESS;
}
void
_CalendarbookUtil::ConvertDateTimeToCalTime(const DateTime& dateTime, calendar_time_s& convertedCalTime)
{
convertedCalTime.type = CALENDAR_TIME_UTIME;
convertedCalTime.time.utime = ConvertDateTimeToEpochTime(dateTime);
}
void
_CalendarbookUtil::ConvertDateToCalTime(const DateTime& dateTime, calendar_time_s& convertedCalTime)
{
convertedCalTime.type = CALENDAR_TIME_LOCALTIME;
convertedCalTime.time.date.year = dateTime.GetYear();
convertedCalTime.time.date.month = dateTime.GetMonth();
convertedCalTime.time.date.mday = dateTime.GetDay();
}
result
_CalendarbookUtil::ConvertRRuleDateTimeStringToDateTime(const String& dateTimeString, DateTime& dateTime, Tizen::Locales::TimeZone& timeZone, bool& isDate)
{
result r = E_SUCCESS;
String dateValue;
String timeValue;
// Split the dateTimeString into date value, time value and time zone
if (dateTimeString.GetLength() == _CALENDARBOOK_DATE_VALUE_STRING_LENGTH)
{
dateValue = dateTimeString;
isDate = true;
}
else if (dateTimeString.GetLength() == _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH)
{
int timeValueIndex = 0;
int suffixIndex = 0;
r = dateTimeString.LastIndexOf(_CALENDARBOOK_TIME_PREFIX, _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1, timeValueIndex);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no T prefix
SysTryReturnResult(NID_SCL, timeValueIndex == _CALENDARBOOK_DATE_VALUE_STRING_LENGTH
, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of T is wrong
r = dateTimeString.LastIndexOf(_CALENDARBOOK_UTC_SUFFIX, _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1, suffixIndex);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no Z suffix
SysTryReturnResult(NID_SCL, suffixIndex == _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH - 1
, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of Z is wrong
r = dateTimeString.SubString(0, _CALENDARBOOK_DATE_VALUE_STRING_LENGTH, dateValue);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
r = dateTimeString.SubString(_CALENDARBOOK_DATE_VALUE_STRING_LENGTH + 1
, _CALENDARBOOK_TIME_VALUE_STRING_LENGTH, timeValue);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
isDate = false;
}
else if (dateTimeString.GetLength() > _CALENDARBOOK_UTC_DATE_TIME_VALUE_STRING_LENGTH) // including timezone ID
{
String timeZoneId;
int dateValueIndex = 0;
r = dateTimeString.LastIndexOf(_CALENDARBOOK_UTC_TZID, dateTimeString.GetLength() - 1, dateValueIndex);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no TZID
SysTryReturnResult(NID_SCL, dateValueIndex == 0, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); //The position of TZID is wrong
r = dateTimeString.LastIndexOf(_CALENDARBOOK_DATE_TIME_DELIMITER, dateTimeString.GetLength() - 1, dateValueIndex);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // There is no TZID
r = dateTimeString.SubString(_CALENDARBOOK_TZID_INDEX, dateValueIndex - _CALENDARBOOK_TZID_INDEX, timeZoneId);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
dateValueIndex += 1;
r = dateTimeString.SubString(dateValueIndex, _CALENDARBOOK_DATE_VALUE_STRING_LENGTH, dateValue);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
r = dateTimeString.SubString(dateValueIndex +_CALENDARBOOK_DATE_VALUE_STRING_LENGTH + 1
, _CALENDARBOOK_TIME_VALUE_STRING_LENGTH, timeValue);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
r = Tizen::Locales::TimeZone::GetTimeZone(timeZoneId, timeZone);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer()); // not supported timezone ID
isDate = false;
}
else
{
SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. date time string = %S", dateTimeString.GetPointer());
return E_INVALID_ARG;
}
int tmpIndex = 0;
String tmpString;
int yearValue = 0;
int monthValue = 0;
int dayValue = 0;
int hourValue = 0;
int minuteValue = 0;
int secondValue = 0;
// Parse date value
r = dateValue.SubString(tmpIndex, _CALENDARBOOK_DATE_YEAR_STRING_LENGTH, tmpString);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
r = Integer::Parse(tmpString, yearValue);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
tmpIndex += _CALENDARBOOK_DATE_YEAR_STRING_LENGTH;
r = dateValue.SubString(tmpIndex, _CALENDARBOOK_DATE_MONTH_STRING_LENGTH, tmpString);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
r = Integer::Parse(tmpString, monthValue);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
tmpIndex += _CALENDARBOOK_DATE_MONTH_STRING_LENGTH;
r = dateValue.SubString(tmpIndex, _CALENDARBOOK_DATE_DAY_STRING_LENGTH, tmpString);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
r = Integer::Parse(tmpString, dayValue);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
tmpIndex += _CALENDARBOOK_DATE_DAY_STRING_LENGTH;
if (!isDate)
{
// Parse time value
tmpIndex = 0;
r = timeValue.SubString(tmpIndex, _CALENDARBOOK_TIME_HOUR_STRING_LENGTH, tmpString);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
r = Integer::Parse(tmpString, hourValue);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
tmpIndex += _CALENDARBOOK_TIME_HOUR_STRING_LENGTH;
r = timeValue.SubString(tmpIndex, _CALENDARBOOK_TIME_MINUTE_STRING_LENGTH, tmpString);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
r = Integer::Parse(tmpString, minuteValue);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
tmpIndex += _CALENDARBOOK_TIME_MINUTE_STRING_LENGTH;
r = timeValue.SubString(tmpIndex, _CALENDARBOOK_TIME_SECOND_STRING_LENGTH, tmpString);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
r = Integer::Parse(tmpString, secondValue);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
tmpIndex += _CALENDARBOOK_TIME_SECOND_STRING_LENGTH;
}
r = dateTime.SetValue(yearValue, monthValue, dayValue, hourValue, minuteValue, secondValue);
SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument is passed. date time string = %S", dateTimeString.GetPointer());
return E_SUCCESS;
}
String
_CalendarbookUtil::ConvertDateTimeToRRuleDateTimeString(const Tizen::Base::DateTime& dateTime, bool isDate)
{
String exdateString;
exdateString.Append(dateTime.GetYear());
if (dateTime.GetMonth() < 10)
{
exdateString.Append(_CALENDARBOOK_ZERO_STRING);
}
exdateString.Append(dateTime.GetMonth());
if (dateTime.GetDay() < 10)
{
exdateString.Append(_CALENDARBOOK_ZERO_STRING);
}
exdateString.Append(dateTime.GetDay());
if (!isDate)
{
exdateString.Append(_CALENDARBOOK_TIME_PREFIX);
if (dateTime.GetHour() < 10)
{
exdateString.Append(_CALENDARBOOK_ZERO_STRING);
}
exdateString.Append(dateTime.GetHour());
if (dateTime.GetMinute() < 10)
{
exdateString.Append(_CALENDARBOOK_ZERO_STRING);
}
exdateString.Append(dateTime.GetMinute());
if (dateTime.GetSecond() < 10)
{
exdateString.Append(_CALENDARBOOK_ZERO_STRING);
}
exdateString.Append(dateTime.GetSecond());
exdateString.Append(_CALENDARBOOK_UTC_SUFFIX);
}
return exdateString;
}
calendar_event_status_e
_CalendarbookUtil::ConvertEventStatusToCSEventStatus(int status)
{
calendar_event_status_e convertedEventStatus = CALENDAR_EVENT_STATUS_NONE;
switch (status)
{
case EVENT_STATUS_NONE:
convertedEventStatus = CALENDAR_EVENT_STATUS_NONE;
break;
case EVENT_STATUS_TENTATIVE:
convertedEventStatus = CALENDAR_EVENT_STATUS_TENTATIVE;
break;
case EVENT_STATUS_CONFIRMED:
convertedEventStatus = CALENDAR_EVENT_STATUS_CONFIRMED;
break;
case EVENT_STATUS_CANCELLED:
convertedEventStatus = CALENDAR_EVENT_STATUS_CANCELLED;
break;
default :
SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", status);
convertedEventStatus = CALENDAR_EVENT_STATUS_NONE;
break;
}
return convertedEventStatus;
}
calendar_event_busy_status_e
_CalendarbookUtil::ConvertBusyStatusToCSEventBusyStatus(int busyStatus)
{
calendar_event_busy_status_e convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
switch (busyStatus)
{
case BUSY_STATUS_FREE:
convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
break;
case BUSY_STATUS_BUSY:
convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_BUSY;
break;
case BUSY_STATUS_UNAVAILABLE:
convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE;
break;
case BUSY_STATUS_TENTATIVE:
convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_TENTATIVE;
break;
default :
SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. busyStatus = %d", busyStatus);
convertedBusyStatus = CALENDAR_EVENT_BUSY_STATUS_FREE;
break;
}
return convertedBusyStatus;
}
calendar_event_priority_e
_CalendarbookUtil::ConvertEventPriorityToCSEventPriority(int priority)
{
calendar_event_priority_e convertedPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
switch (priority)
{
case EVENT_PRIORITY_LOW:
convertedPriority = CALENDAR_EVENT_PRIORITY_LOW;
break;
case EVENT_PRIORITY_NORMAL:
convertedPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
break;
case EVENT_PRIORITY_HIGH:
convertedPriority = CALENDAR_EVENT_PRIORITY_HIGH;
break;
default :
SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", priority);
convertedPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
break;
}
return convertedPriority;
}
calendar_sensitivity_e
_CalendarbookUtil::ConvertSensitivityToCSSensitivity(int sensitivity)
{
calendar_sensitivity_e convertedSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
switch (sensitivity)
{
case SENSITIVITY_PUBLIC:
convertedSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
break;
case SENSITIVITY_PRIVATE:
convertedSensitivity = CALENDAR_SENSITIVITY_PRIVATE;
break;
case SENSITIVITY_CONFIDENTIAL:
convertedSensitivity = CALENDAR_SENSITIVITY_CONFIDENTIAL;
break;
default :
SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. sensitivity = %d", sensitivity);
convertedSensitivity = CALENDAR_SENSITIVITY_PUBLIC;
break;
}
return convertedSensitivity;
}
calendar_todo_status_e
_CalendarbookUtil::ConvertTodoStatusToCSTodoStatus(int status)
{
calendar_todo_status_e convertedTodoStatus = CALENDAR_TODO_STATUS_NONE;
switch (status)
{
case TODO_STATUS_NONE:
convertedTodoStatus = CALENDAR_TODO_STATUS_NONE;
break;
case TODO_STATUS_NEEDS_ACTION:
convertedTodoStatus = CALENDAR_TODO_STATUS_NEEDS_ACTION;
break;
case TODO_STATUS_COMPLETED:
convertedTodoStatus = CALENDAR_TODO_STATUS_COMPLETED;
break;
case TODO_STATUS_IN_PROCESS:
convertedTodoStatus = CALENDAR_TODO_STATUS_IN_PROCESS;
break;
case TODO_STATUS_CANCELLED:
convertedTodoStatus = CALENDAR_TODO_STATUS_CANCELED;
break;
default :
SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. status = %d", status);
convertedTodoStatus = CALENDAR_TODO_STATUS_NONE;
break;
}
return convertedTodoStatus;
}
calendar_todo_priority_e
_CalendarbookUtil::ConvertTodoPriorityToCSTodoPriority(int priority)
{
calendar_todo_priority_e convertedPriority = CALENDAR_TODO_PRIORITY_NONE;
switch (priority)
{
case TODO_PRIORITY_LOW:
convertedPriority = CALENDAR_TODO_PRIORITY_LOW;
break;
case TODO_PRIORITY_NORMAL:
convertedPriority = CALENDAR_TODO_PRIORITY_NORMAL;
break;
case TODO_PRIORITY_HIGH:
convertedPriority = CALENDAR_TODO_PRIORITY_HIGH;
break;
default :
SysLogException(NID_SCL, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. priority = %d", priority);
convertedPriority = CALENDAR_TODO_PRIORITY_NONE;
break;
}
return convertedPriority;
}
int
_CalendarbookUtil::ConvertCalendarItemTypeToCSCalendarbookType(int itemType)
{
int storeType = CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO;
switch (itemType)
{
case CALENDAR_ITEM_TYPE_EVENT_ONLY:
storeType = CALENDAR_BOOK_TYPE_EVENT;
break;
case CALENDAR_ITEM_TYPE_TODO_ONLY:
storeType = CALENDAR_BOOK_TYPE_TODO;
break;
case CALENDAR_ITEM_TYPE_EVENT_AND_TODO:
storeType = CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO;
break;
default :
storeType = CALENDAR_BOOK_TYPE_EVENT | CALENDAR_BOOK_TYPE_TODO;
break;
}
return storeType;
}
EventCategory
_CalendarbookUtil::ConvertCSCategoriesToEventCategory(const char* pCategories)
{
result r = E_SUCCESS;
EventCategory eventCategory = EVENT_CATEGORY_APPOINTMENT;
String tmpString(pCategories);
String delim(_EVENT_CATEGORY_DELIMITER);
String token;
StringTokenizer strTok(tmpString, delim);
while (strTok.HasMoreTokens())
{
r = strTok.GetNextToken(token);
SysTryReturn(NID_SCL, r == E_SUCCESS, EVENT_CATEGORY_APPOINTMENT, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
if (token == _EVENT_CATEGORY_APPOINTMENT_STRING)
{
eventCategory = EVENT_CATEGORY_APPOINTMENT;
break;
}
else if (token == _EVENT_CATEGORY_ANNIVERSARY_STRING)
{
eventCategory = EVENT_CATEGORY_ANNIVERSARY;
break;
}
}
return eventCategory;
}
int
_CalendarbookUtil::GetMaxDaysOfMonth(int year, int month)
{
int maxDaysOfMonth = 0;
Tizen::Locales::Calendar* pGregorianCalendar = Tizen::Locales::Calendar::CreateInstanceN(Tizen::Locales::CALENDAR_GREGORIAN);
pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_YEAR, year);
pGregorianCalendar->SetTimeField(Tizen::Locales::TIME_FIELD_MONTH, month);
maxDaysOfMonth = pGregorianCalendar->GetActualMaxTimeField(Tizen::Locales::TIME_FIELD_DAY_OF_MONTH);
delete pGregorianCalendar;
return maxDaysOfMonth;
}
bool
_CalendarbookUtil::CheckValidDateTime(const DateTime& dateTime)
{
if (dateTime < _CalendarbookImpl::GetMinDateTime() || dateTime > _CalendarbookImpl::GetMaxDateTime())
{
return false;
}
return true;
}
}} // Tizen::Social
|