20bad9574f84bfbeee720c9d8121f5a214a29ec8
[platform/framework/web/wrt-plugins-tizen.git] / src / Calendar / JSCalendarItemProperties.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include <ctime>
19 #include <CommonsJavaScript/PrivateObject.h>
20 #include <CommonsJavaScript/Converter.h>
21 #include <CommonsJavaScript/JSUtils.h>
22 #include <JSTizenException.h>
23 #include <JSTizenExceptionFactory.h>
24 #include <SecurityExceptions.h>
25 #include <TimeUtilConverter.h>
26 #include <JSTZDate.h>
27 #include <JSSimpleCoordinates.h>
28 #include "EventAlarm.h"
29 #include "EventId.h"
30 #include "ICalendar.h"
31 #include "CalendarFactory.h"
32 #include <DurationProperties.h>
33 #include "JSCalendarItemProperties.h"
34 #include "CalendarConverter.h"
35 #include "JSCalendarEventId.h"
36 #include "JSCalendarAlarm.h"
37 #include "JSCalendarAttendee.h"
38 #include "JSCalendarEvent.h"
39 #include "JSCalendarTask.h"
40 #include "plugin_config.h"
41 #include <GlobalContextManager.h>
42 #include <TimeTracer.h>
43 #include <Logger.h>
44
45 using namespace WrtDeviceApis::Commons;
46 using namespace WrtDeviceApis::CommonsJavaScript;
47 using namespace DeviceAPI::Common;
48 using namespace DeviceAPI::Time;
49
50 namespace DeviceAPI {
51 namespace Calendar {
52
53 #define TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME "CalendarItemProperties"
54
55 JSClassDefinition JSCalendarItemProperties::m_classInfo = {
56     0,
57     kJSClassAttributeNone,
58     TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME,
59     0,
60     m_property,
61     m_function,
62     initialize,
63     finalize,
64     NULL, //hasProperty,
65     NULL, //getProperty,
66     NULL, //setProperty,
67     NULL, //DeleteProperty,
68     NULL, //GetPropertyNames,
69     NULL, //CallAsFunction,
70     NULL, //CallAsConstructor,
71     NULL, //HasInstance,
72     NULL  //ConvertToType
73 };
74
75 JSStaticValue JSCalendarItemProperties::m_property[] = {
76     // Item Properties
77     { TIZEN_CALENDAR_ITEM_DESCRIPTION, getPropertyDescription, setPropertyDescription, kJSPropertyAttributeNone },
78     { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary, setPropertySummary, kJSPropertyAttributeNone },
79     { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartTime, setPropertyStartTime, kJSPropertyAttributeNone },
80     { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation, setPropertyLocation, kJSPropertyAttributeNone },
81     { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation, setPropertyGeolocation, kJSPropertyAttributeNone },
82     { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer, setPropertyOrganizer, kJSPropertyAttributeNone },
83     { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility, setPropertyVisibility, kJSPropertyAttributeNone },
84     { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus, setPropertyStatus, kJSPropertyAttributeNone },
85     { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms, setPropertyAlarms, kJSPropertyAttributeNone },
86     { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories, setPropertyCategories, kJSPropertyAttributeNone },
87     { TIZEN_CALENDAR_ITEM_DURATION, getPropertyDuration, setPropertyDuration, kJSPropertyAttributeNone },
88     { TIZEN_CALENDAR_ITEM_IS_ALL_DAY, getPropertyIsAllDay, setPropertyIsAllDay, kJSPropertyAttributeNone },
89     { TIZEN_CALENDAR_ITEM_ATTENDEES, getPropertyAttendees, setPropertyAttendees, kJSPropertyAttributeNone },
90     { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability, setPropertyAvailability, kJSPropertyAttributeNone },
91     { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate, setPropertyDueDate, kJSPropertyAttributeNone },
92     { TIZEN_CALENDAR_TASK_COMPLETED_DATE, getPropertyCompletedDate, setPropertyCompletedDate, kJSPropertyAttributeNone },
93     { TIZEN_CALENDAR_TASK_PROGRESS, getPropertyProgress, setPropertyProgress, kJSPropertyAttributeNone },
94     { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority, setPropertyPriority, kJSPropertyAttributeNone },
95     { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate, setPropertyEndDate, kJSPropertyAttributeNone },
96     { TIZEN_CALENDAR_EVENT_LAST_MODIFICATION_DATE, getPropertyLastModificationDate, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
97         { TIZEN_CALENDAR_ITEM_CALENDAR_ID, getPropertyCalendarId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
98
99     { 0, 0, 0, 0 }
100 };
101
102 JSStaticFunction JSCalendarItemProperties::m_function[] = {
103     { CALENDAR_FUNCTION_API_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
104     { CALENDAR_FUNCTION_API_CLONE, clone, kJSPropertyAttributeNone },
105
106     { 0, 0, 0 }
107 };
108
109 JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
110
111 void JSCalendarItemProperties::initialize(JSContextRef context,
112         JSObjectRef object)
113 {
114     if (!JSObjectGetPrivate(object)) {
115         LoggerD("Create calendar item private object.");
116         CalendarEventPtr item( new CalendarEvent() );
117         CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
118         if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
119             delete priv;
120         }
121     } else {
122         LoggerD("Private object already set.");
123     }
124 }
125
126 void JSCalendarItemProperties::finalize(JSObjectRef object)
127 {
128     CalendarItemPropertiesPrivObject *priv = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
129     if (priv) {
130         delete priv;
131         JSObjectSetPrivate(object, NULL);
132     }
133 }
134
135 const JSClassRef JSCalendarItemProperties::getClassRef()
136 {
137     if (!m_jsClassRef) {
138         m_jsClassRef = JSClassCreate(&m_classInfo);
139     }
140     return m_jsClassRef;
141 }
142
143 const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
144 {
145     return &m_classInfo;
146 }
147
148 CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
149 {
150     CalendarItemPropertiesPrivObject *priv =
151         static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
152     if (!priv) {
153         ThrowMsg(NullPointerException, "Private object is null");
154     }
155     CalendarEventPtr result = priv->getObject();
156     if (!result) {
157         ThrowMsg(NullPointerException, "Private object is null");
158     }
159     return result;
160 }
161
162 void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
163         JSContextRef ctx,
164         const JSObjectRef object)
165 {
166     Try
167     {
168         CalendarItemPropertiesPrivObject *priv =
169             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
170         delete priv;
171         priv = new CalendarItemPropertiesPrivObject(ctx, event);
172         if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
173             delete priv;
174         }
175     }
176     Catch(Exception)
177     {
178         LoggerE("Error during replacing event object");
179     }
180 }
181
182 JSObjectRef JSCalendarItemProperties::createJSCalendarItemProperties(JSContextRef context, CalendarEventPtr item)
183 {
184     CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
185     return JSObjectMake(context, getClassRef(), priv);
186 }
187
188 JSValueRef JSCalendarItemProperties::convertToString(JSContextRef context,
189         JSObjectRef object,
190         JSObjectRef thisObject,
191         size_t argumentCount,
192         const JSValueRef arguments[],
193         JSValueRef* exception)
194 {
195         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
196     CalendarItemPropertiesPrivObject *privateObject =
197         static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
198
199     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
200
201     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
202
203     Try
204     {
205         if (!privateObject) {
206             ThrowMsg(ConversionException, "Object is null.");
207         }
208
209         CalendarEventPtr item = privateObject->getObject();
210         if (!item) {
211             ThrowMsg(ConversionException, "Parameter conversion failed.");
212         }
213
214         CalendarConverter converter(context);
215
216         CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
217         if (argumentCount>=1) {
218             format = converter.toVObjectFormat(converter.toString(arguments[0]));
219         } else {
220             ThrowMsg(ConversionException, "Wrong parameter type.");
221         }
222
223         ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
224         calendar->setType(item->getCalendarType());
225
226         IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
227         dplEvent->setEvent(item);
228         dplEvent->setFormat(format);
229         dplEvent->setForSynchronousCall();
230         calendar->exportEventToString(dplEvent);
231
232         if (dplEvent->getResult()) {
233                         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
234             return converter.toJSValueRef(dplEvent->getEventString());
235         } else {
236             ThrowMsg(UnknownException, "Converting to string failed by unknown reason.");
237         }
238     }
239     Catch(UnsupportedException)
240     {
241                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
242         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
243     }
244     Catch(InvalidArgumentException)
245     {
246                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
247         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
248     }
249     Catch(ConversionException)
250     {
251                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
252         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
253     }
254     Catch (NotFoundException)
255     {
256                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
257         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
258     }
259     Catch(Exception)
260     {
261                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
262         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
263     }
264 }
265
266 JSValueRef JSCalendarItemProperties::clone(JSContextRef context,
267         JSObjectRef object,
268         JSObjectRef thisObject,
269         size_t argumentCount,
270         const JSValueRef arguments[],
271         JSValueRef* exception)
272 {
273         TIME_TRACER_ITEM_BEGIN("clone(TASK)", 0);
274         TIME_TRACER_ITEM_BEGIN("clone(EVENT)", 0);
275     CalendarItemPropertiesPrivObject *privateObject =
276         static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
277
278     AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CLONE);
279
280     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
281
282     Try
283     {
284         if (!privateObject) {
285             ThrowMsg(ConversionException, "Object is null.");
286         }
287
288         CalendarEventPtr item = privateObject->getObject(); // item to copy
289         if (!item) {
290             ThrowMsg(ConversionException, "Parameter conversion failed.");
291         }
292         JSContextRef globalContext = privateObject->getContext();
293
294         // Call the copy constructor.
295         CalendarEventPtr clonedItem( new CalendarEvent(*item));
296
297         // Reset the id.
298         clonedItem->resetId();
299         clonedItem->setRecurrenceId(UNDEFINED_ITEM_ID);
300
301                 if (CalendarEvent::TASK_TYPE==clonedItem->getCalendarType()) {
302                         TIME_TRACER_ITEM_END("clone(TASK)", 0);
303                 return JSCalendarTask::createJSCalendarTask(context, clonedItem);
304                 } else if (CalendarEvent::EVENT_TYPE==clonedItem->getCalendarType()) {
305                         TIME_TRACER_ITEM_END("clone(EVENT)", 0);
306             // Use global context for potential async api invocation.
307             return JSCalendarEvent::createJSCalendarEvent(globalContext, clonedItem);
308                 } else {
309                         ThrowMsg(ConversionException, "Wrong object type.");
310                 }
311     }
312     Catch(UnsupportedException)
313     {
314                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
315         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
316     }
317     Catch(InvalidArgumentException)
318     {
319                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
320         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
321     }
322     Catch(ConversionException)
323     {
324                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
325         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
326     }
327     Catch (NotFoundException)
328     {
329                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
330         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
331     }
332     Catch(Exception)
333     {
334                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
335         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
336     }
337 }
338
339 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
340         JSObjectRef object,
341         JSStringRef propertyName,
342         JSValueRef* exception)
343 {
344     Try
345     {
346         Converter converter(context);
347         CalendarEventPtr event = getPrivateObject(object);
348         return converter.toJSValueRef(event->getDescription());
349     }
350     Catch(Exception)
351     {
352                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
353     }
354     return JSValueMakeUndefined(context);
355 }
356
357 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
358         JSObjectRef object,
359         JSStringRef propertyName,
360         JSValueRef value,
361         JSValueRef* exception)
362 {
363     Try
364     {
365         Converter converter(context);
366         CalendarEventPtr event = getPrivateObject(object);
367         std::string description = converter.toString(value);
368         event->setDescription(description);
369         return true;
370     }
371     Catch(Exception)
372     {
373                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
374     }
375
376     return true;
377 }
378
379 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
380         JSObjectRef object,
381         JSStringRef propertyName,
382         JSValueRef* exception)
383 {
384     Try
385     {
386         Converter converter(context);
387         CalendarEventPtr event = getPrivateObject(object);
388         return converter.toJSValueRef(event->getSubject());
389     }
390     Catch(Exception)
391     {
392                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
393     }
394     return JSValueMakeUndefined(context);
395 }
396
397 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
398         JSObjectRef object,
399         JSStringRef propertyName,
400         JSValueRef value,
401         JSValueRef* exception)
402 {
403     Try
404     {
405         Converter converter(context);
406         CalendarEventPtr event = getPrivateObject(object);
407         std::string subject = converter.toString(value);
408         event->setSubject(subject);
409         return true;
410     }
411     Catch(Exception)
412     {
413                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
414     }
415
416     return true;
417 }
418
419 JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context,
420         JSObjectRef object,
421         JSStringRef propertyName,
422         JSValueRef* exception)
423 {
424     Try
425     {
426         CalendarItemPropertiesPrivObject *privateObject =
427             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
428         TimeUtilConverter timeConverter(context);
429         CalendarEventPtr event = privateObject->getObject();
430
431         LoggerI("start time before converted to TZDate: "<<event->getStartTime()<<", time zone: "<<event->getTimeZone());
432         if (UNDEFINED_TIME==event->getStartTime()) {
433             return JSValueMakeUndefined(context);
434         } else {
435             return timeConverter.toJSValueRefTZDate((double)(event->getStartTime()*1000.0), event->getTimeZone());
436         }
437     }
438     Catch(Exception)
439     {
440                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
441     }
442     return JSValueMakeUndefined(context);
443 }
444
445 bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context,
446         JSObjectRef object,
447         JSStringRef propertyName,
448         JSValueRef value,
449         JSValueRef* exception)
450 {
451     Try
452     {
453         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
454             ThrowMsg(ConversionException, "Wrong parameter type.");
455         }
456
457         CalendarEventPtr event = getPrivateObject(object);
458         TimeUtilConverter converter(context);
459         std::time_t duration = event->getEndTime() - event->getStartTime();
460         if (duration<0) {
461             duration = 0;
462         }
463
464         long long int startTime = (long long int) (converter.getTimeInMilliseconds(value)/1000);
465         event->setStartTime(startTime);
466         event->setEndTime(startTime + duration);
467
468         std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
469         event->setTimeZone(timeZone);
470         return true;
471     }
472     Catch(Exception)
473     {
474                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
475     }
476
477     return true;
478 }
479
480 JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
481         JSObjectRef object,
482         JSStringRef propertyName,
483         JSValueRef* exception)
484 {
485     Try
486     {
487         Converter converter(context);
488         CalendarEventPtr event = getPrivateObject(object);
489         return converter.toJSValueRef(event->getLocation());
490     }
491     Catch(Exception)
492     {
493                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
494     }
495     return JSValueMakeUndefined(context);
496 }
497
498 bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
499         JSObjectRef object,
500         JSStringRef propertyName,
501         JSValueRef value,
502         JSValueRef* exception)
503 {
504     Try
505     {
506         Converter converter(context);
507         CalendarEventPtr event = getPrivateObject(object);
508         std::string location = converter.toString(value);
509         event->setLocation(location);
510         return true;
511     }
512     Catch(Exception)
513     {
514                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
515     }
516
517     return true;
518 }
519
520 JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
521         JSObjectRef object,
522         JSStringRef propertyName,
523         JSValueRef* exception)
524 {
525     Try
526     {
527             CalendarEventPtr item = getPrivateObject(object);
528                 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
529
530         CalendarConverter converter(globalContext);
531
532                 if(item->getCategoriesJSRef()) {
533                         return item->getCategoriesJSRef();
534                 } else {
535                         LoggerD("Create a JS object for categories.");
536                 StringArrayPtr categories = item->getCategories();
537                         JSValueRef jsCategories = converter.toJSValueRefStringArray(categories);
538                         item->setCategoriesJSRef(converter.toJSObjectRef(jsCategories));
539
540                         JSValueProtect(globalContext, jsCategories);
541                         item->setContext(globalContext);
542             return jsCategories;
543                 }
544     }
545     Catch(Exception)
546     {
547                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
548     }
549     return JSValueMakeUndefined(context);
550 }
551
552 bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
553         JSObjectRef object,
554         JSStringRef propertyName,
555         JSValueRef value,
556         JSValueRef* exception)
557 {
558     Try
559     {
560         CalendarEventPtr event = getPrivateObject(object);
561         CalendarConverter converter(context);
562                 event->setCategories(converter.toStringArray(value));
563         return true;
564     }
565     Catch(Exception)
566     {
567                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
568     }
569
570     return true;
571 }
572
573 JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
574         JSObjectRef object,
575         JSStringRef propertyName,
576         JSValueRef* exception)
577 {
578     Try
579     {
580         CalendarConverter converter(context);
581         CalendarEventPtr event = getPrivateObject(object);
582         std::string status = converter.toTizenValue(event->getStatus());
583         return converter.toJSValueRef(status);
584     }
585     Catch(Exception)
586     {
587                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
588     }
589     return JSValueMakeUndefined(context);
590 }
591
592 bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
593         JSObjectRef object,
594         JSStringRef propertyName,
595         JSValueRef value,
596         JSValueRef* exception)
597 {
598     CalendarEventPtr event(NULL);
599     Try
600     {
601         event = getPrivateObject(object);
602         CalendarConverter converter(context);
603         CalendarEvent::EventStatus status =
604             converter.toEventStatus(converter.toString(value));
605         event->setStatus(status);
606         return true;
607     }
608     Catch(Exception)
609     {
610                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
611     }
612
613     return true;
614 }
615
616 JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
617         JSObjectRef object,
618         JSStringRef propertyName,
619         JSValueRef* exception)
620 {
621     Try
622     {
623         CalendarEventPtr event = getPrivateObject(object);
624
625         JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
626         if (NULL == jsResult) {
627             ThrowMsg(NullPointerException, "Can not create array object.");
628         }
629         for( unsigned int i=0; i<event->getAlarms()->size(); i++) {
630             if (!JSSetArrayElement(context, jsResult, i, JSCalendarAlarm::createJSCalendarAlarm(context, event->getAlarms()->at(i)))) {
631                ThrowMsg(UnknownException, "Can not insert value into array.");
632             }
633         }
634         return jsResult;
635     }
636     Catch(Exception)
637     {
638                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
639     }
640     return JSValueMakeUndefined(context);
641 }
642
643 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
644         JSObjectRef object,
645         JSStringRef propertyName,
646         JSValueRef value,
647         JSValueRef* exception)
648 {
649     CalendarEventPtr event(NULL);
650     Try
651     {
652         event = getPrivateObject(object);
653         CalendarConverter converter(context);
654
655         EventAlarmListPtr alarms = converter.toVectorOfEventAlarmsFromReference(value);
656
657         event->setAlarms(alarms);
658         return true;
659     }
660     Catch(Exception)
661     {
662                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
663     }
664
665     return true;
666 }
667
668 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
669         JSObjectRef object,
670         JSStringRef propertyName,
671         JSValueRef* exception)
672 {
673     Try
674     {
675         Converter converter(context);
676         CalendarEventPtr event = getPrivateObject(object);
677         return converter.toJSValueRef(event->getOrganizer());
678     }
679     Catch(Exception)
680     {
681                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
682     }
683     return JSValueMakeUndefined(context);
684 }
685
686 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
687         JSObjectRef object,
688         JSStringRef propertyName,
689         JSValueRef value,
690         JSValueRef* exception)
691 {
692     Try
693     {
694         Converter converter(context);
695         CalendarEventPtr event = getPrivateObject(object);
696         std::string organizer = converter.toString(value);
697         event->setOrganizer(organizer);
698         return true;
699     }
700     Catch(Exception)
701     {
702                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
703     }
704
705     return true;
706 }
707
708 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
709         JSObjectRef object,
710         JSStringRef propertyName,
711         JSValueRef* exception)
712 {
713     Try
714     {
715         CalendarConverter converter(context);
716         CalendarEventPtr event = getPrivateObject(object);
717         std::string visibility = converter.toTizenValue(event->getVisibility());
718         return converter.toJSValueRef(visibility);
719     }
720     Catch(Exception)
721     {
722                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
723     }
724     return JSValueMakeUndefined(context);
725 }
726
727 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
728         JSObjectRef object,
729         JSStringRef propertyName,
730         JSValueRef value,
731         JSValueRef* exception)
732 {
733     CalendarEventPtr event(NULL);
734     Try
735     {
736         event = getPrivateObject(object);
737         CalendarConverter converter(context);
738         CalendarEvent::EventVisibility visibility =
739             converter.toEventVisibility(converter.toString(value));
740         event->setVisibility(visibility);
741         return true;
742     }
743     Catch(Exception)
744     {
745                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
746     }
747
748     return true;
749 }
750
751 JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
752         JSObjectRef object,
753         JSStringRef propertyName,
754         JSValueRef* exception)
755 {
756     Try
757     {
758         CalendarEventPtr item = getPrivateObject(object);
759         if( UNDEFINED_GEO==item->getGeolocation()->getLatitude() ) {
760                         return JSValueMakeUndefined(context);
761                 } else {
762                         return DeviceAPI::Tizen::JSSimpleCoordinates::createJSObject(context, item->getGeolocation());
763                 }
764     }
765     Catch(Exception)
766     {
767                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
768     }
769
770     return JSValueMakeUndefined(context);
771 }
772
773 bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
774         JSObjectRef object,
775         JSStringRef propertyName,
776         JSValueRef value,
777         JSValueRef* exception)
778 {
779     Try
780     {
781         CalendarEventPtr item = getPrivateObject(object);
782
783                 if (JSValueIsNull(context, value) || JSValueIsUndefined(context, value)) {
784                 item->getGeolocation()->setLatitude(UNDEFINED_GEO);
785                 item->getGeolocation()->setLongitude(UNDEFINED_GEO);
786                 } else {
787                 DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation = DeviceAPI::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
788
789                 item->setGeolocation(geoLocation);
790                 }
791         return true;
792     }
793     Catch(Exception)
794     {
795                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
796     }
797
798     return true;
799 }
800
801 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
802         JSObjectRef object,
803         JSStringRef propertyName,
804         JSValueRef* exception)
805 {
806     Try
807     {
808         CalendarEventPtr item = getPrivateObject(object);
809         TimeUtilConverter converter(context);
810
811                 DurationProperties duration;
812                 if(UNDEFINED_TIME!=item->getDuration()->length) {
813                         duration.length = item->getDuration()->length;
814                         duration.unit = item->getDuration()->unit;
815                         LoggerD("Duration length: "<<duration.length<<", unit: "<<duration.unit);
816                         return converter.makeDurationObject( duration );
817                 }
818
819                 // Alternatively generate the duration object using start/end time.
820                 if(UNDEFINED_TIME==item->getStartTime() || UNDEFINED_TIME==item->getEndTime()) {
821                         LoggerD("Start or end time is not defined.");
822                     return JSValueMakeUndefined(context);
823                 }
824
825         long long length = item->getEndTime() - item->getStartTime(); // in seconds only
826         LoggerD("item->getStartTime():"<< item->getStartTime() << ", length:" << length);
827                 duration.length = length;
828                 duration.unit = SECONDS_UNIT;
829
830         return converter.makeDurationObject( duration );
831     }
832     Catch(Exception)
833     {
834                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
835     }
836     return JSValueMakeUndefined(context);
837 }
838
839 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
840         JSObjectRef object,
841         JSStringRef propertyName,
842         JSValueRef value,
843         JSValueRef* exception)
844 {
845     Try
846     {
847         CalendarEventPtr event = getPrivateObject(object);
848         TimeUtilConverter converter(context);
849         long length = converter.getDurationLength(value);
850         int unit = converter.getDurationUnit(value);
851         if (length < 0) {
852             DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR);
853             return false;
854         }
855         if( SECONDS_UNIT==unit ) {
856             event->setEndTime(event->getStartTime() + length);
857         } else if ( MINUTES_UNIT==unit ) {
858             event->setEndTime(event->getStartTime() + length*60);
859         } else if ( HOURS_UNIT==unit ) {
860             event->setEndTime(event->getStartTime() + length*60*60);
861         } else if ( DAYS_UNIT==unit ) {
862             event->setEndTime(event->getStartTime() + length*24*60*60);
863         } else if ( MSECS_UNIT==unit ) {
864             event->setEndTime(event->getStartTime() + length/1000);
865         } else {
866             DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::INVALID_VALUES_ERROR);
867             return false;
868         }
869
870                 event->getDuration()->length = length;
871                 event->getDuration()->unit = unit;
872
873         return true;
874     }
875     Catch(Exception)
876     {
877                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
878     }
879
880     return true;
881 }
882
883 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
884         JSObjectRef object,
885         JSStringRef propertyName,
886         JSValueRef* exception)
887 {
888     Try
889     {
890         CalendarConverter converter(context);
891         CalendarEventPtr event = getPrivateObject(object);
892         return converter.toJSValueRef(event->getIsAllDay());
893     }
894     Catch(Exception)
895     {
896                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
897     }
898     return JSValueMakeUndefined(context);
899 }
900
901 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
902         JSObjectRef object,
903         JSStringRef propertyName,
904         JSValueRef value,
905         JSValueRef* exception)
906 {
907     Try
908     {
909         CalendarEventPtr event = getPrivateObject(object);
910         Converter converter(context);
911         event->setIsAllDay(converter.toBool(value));
912         return true;
913     }
914     Catch(Exception)
915     {
916                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
917     }
918
919     return true;
920 }
921
922 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
923         JSObjectRef object,
924         JSStringRef propertyName,
925         JSValueRef* exception)
926 {
927     Try
928     {
929         CalendarConverter converter(context);
930         CalendarEventPtr event = getPrivateObject(object);
931         std::string availability = converter.toTizenValue(event->getAvailability());
932         return converter.toJSValueRef(availability);
933     }
934     Catch(Exception)
935     {
936                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
937     }
938     return JSValueMakeUndefined(context);
939 }
940
941 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
942         JSObjectRef object,
943         JSStringRef propertyName,
944         JSValueRef value,
945         JSValueRef* exception)
946 {
947     CalendarEventPtr event(NULL);
948     Try
949     {
950         event = getPrivateObject(object);
951         CalendarConverter converter(context);
952         CalendarEvent::EventAvailability availability =
953             converter.toEventAvailability(converter.toString(value));
954         event->setAvailability(availability);
955         return true;
956     }
957     Catch(Exception)
958     {
959                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
960     }
961
962     return true;
963 }
964
965 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
966         JSObjectRef object,
967         JSStringRef propertyName,
968         JSValueRef* exception)
969 {
970     Try
971     {
972         CalendarEventPtr event = getPrivateObject(object);
973         EventAttendeeListPtr attendees = event->getAttendees();
974         if (attendees) {
975             JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
976             if (NULL == jsResult) {
977                 ThrowMsg(NullPointerException, "Can not create array object.");
978             }
979             for(unsigned int i=0; i<attendees->size(); i++) {
980                 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
981                    ThrowMsg(UnknownException, "Can not insert value into array.");
982                 }
983             }
984             return jsResult;
985         }
986     }
987     Catch(Exception)
988     {
989                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
990     }
991     return JSValueMakeUndefined(context);
992 }
993
994 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
995         JSObjectRef object,
996         JSStringRef propertyName,
997         JSValueRef value,
998         JSValueRef* exception)
999 {
1000     Try
1001     {
1002         CalendarEventPtr event = getPrivateObject(object);
1003         CalendarConverter converter(context);
1004         event->setAttendees(converter.toVectorOfAttendeesFromReference(value));
1005         return true;
1006     }
1007     Catch(Exception)
1008     {
1009                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1010     }
1011
1012     return true;
1013 }
1014
1015 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1016         JSObjectRef object,
1017         JSStringRef propertyName,
1018         JSValueRef* exception)
1019 {
1020     Try
1021         {
1022         CalendarItemPropertiesPrivObject *privateObject =
1023             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1024         CalendarEventPtr task = privateObject->getObject();
1025         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1026             return JSValueMakeUndefined(context);
1027         }
1028         if (!task) {
1029             ThrowMsg(NullPointerException, "Task object is NULL.");
1030         }
1031
1032         if (UNDEFINED_TIME==task->getEndTime()) {
1033             return JSValueMakeUndefined(context);
1034         } else {
1035             TimeUtilConverter timeConverter(context);
1036             return timeConverter.toJSValueRefTZDate((double)(task->getEndTime()*1000.0), task->getTimeZone());
1037         }
1038     }
1039     Catch(Exception)
1040     {
1041                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1042     }
1043     return JSValueMakeUndefined(context);
1044 }
1045
1046 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1047         JSObjectRef object,
1048         JSStringRef propertyName,
1049         JSValueRef value,
1050         JSValueRef* exception)
1051 {
1052     Try
1053     {
1054         CalendarEventPtr task = getPrivateObject(object);
1055         if (!task) {
1056             ThrowMsg(NullPointerException, "Task object is NULL.");
1057         }
1058         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1059             ThrowMsg(InvalidArgumentException, "Wrong type of calendar.");
1060         }
1061         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1062             ThrowMsg(ConversionException, "Wrong parameter type.");
1063         }
1064
1065         TimeUtilConverter converter(context);
1066         long long int dueDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1067
1068         task->setEndTime(dueDate);
1069
1070         if( task->getTimeZone().empty() ) {
1071             std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1072             task->setTimeZone(timeZone);
1073         }
1074         return true;
1075     }
1076     Catch(Exception)
1077     {
1078                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1079     }
1080
1081     return true;
1082 }
1083
1084 JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
1085         JSObjectRef object,
1086         JSStringRef propertyName,
1087         JSValueRef* exception)
1088 {
1089     Try
1090     {
1091         CalendarItemPropertiesPrivObject *privateObject =
1092             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1093         CalendarEventPtr task = privateObject->getObject();
1094         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1095             return JSValueMakeUndefined(context);
1096         }
1097         if (!task) {
1098             ThrowMsg(NullPointerException, "Task object is NULL.");
1099         }
1100
1101         if (UNDEFINED_TIME==task->getCompletedDate()) {
1102             return JSValueMakeUndefined(context);
1103         } else {
1104             TimeUtilConverter timeConverter(context);
1105             return timeConverter.toJSValueRefTZDate((double)(task->getCompletedDate()*1000.0), task->getTimeZone());
1106         }
1107     }
1108     Catch(Exception)
1109     {
1110                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1111     }
1112     return JSValueMakeUndefined(context);
1113 }
1114
1115 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1116         JSObjectRef object,
1117         JSStringRef propertyName,
1118         JSValueRef value,
1119         JSValueRef* exception)
1120 {
1121     Try
1122     {
1123         CalendarEventPtr task = getPrivateObject(object);
1124         if (!task) {
1125             ThrowMsg(NullPointerException, "Task object is NULL.");
1126         }
1127         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1128             ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1129         }
1130         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1131             ThrowMsg(ConversionException, "Wrong parameter type.");
1132         }
1133
1134         TimeUtilConverter converter(context);
1135         long long int completedDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1136
1137         task->setCompletedDate(completedDate);
1138
1139         if( task->getTimeZone().empty() ) {
1140             std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1141             task->setTimeZone(timeZone);
1142         }
1143         return true;
1144     }
1145     Catch(Exception)
1146     {
1147                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1148     }
1149
1150     return true;
1151 }
1152
1153 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1154         JSObjectRef object,
1155         JSStringRef propertyName,
1156         JSValueRef* exception)
1157 {
1158     Try
1159     {
1160         CalendarEventPtr task = getPrivateObject(object);
1161         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1162             return JSValueMakeUndefined(context);
1163         }
1164
1165         Converter converter(context);
1166         return converter.toJSValueRef(task->getProgress());
1167     }
1168     Catch(Exception)
1169     {
1170                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1171     }
1172     return JSValueMakeUndefined(context);
1173 }
1174
1175 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1176         JSObjectRef object,
1177         JSStringRef propertyName,
1178         JSValueRef value,
1179         JSValueRef* exception)
1180 {
1181     Try
1182     {
1183         CalendarEventPtr task = getPrivateObject(object);
1184         if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1185             return JSValueMakeUndefined(context);
1186         }
1187
1188         Converter converter(context);
1189         int progress = converter.toInt(value);
1190         task->setProgress(progress);
1191         return true;
1192     }
1193     Catch(Exception)
1194     {
1195                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1196     }
1197
1198     return true;
1199 }
1200
1201 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1202         JSObjectRef object,
1203         JSStringRef propertyName,
1204         JSValueRef* exception)
1205 {
1206     Try
1207     {
1208         CalendarConverter converter(context);
1209         CalendarEventPtr item = getPrivateObject(object);
1210         if (!item) {
1211             ThrowMsg(NullPointerException, "Item object is NULL.");
1212         }
1213
1214         std::string priority = converter.toTizenValue(item->getPriority());
1215         return converter.toJSValueRef(priority);
1216     }
1217     Catch(Exception)
1218     {
1219                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1220     }
1221     return JSValueMakeUndefined(context);
1222 }
1223
1224 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1225         JSObjectRef object,
1226         JSStringRef propertyName,
1227         JSValueRef value,
1228         JSValueRef* exception)
1229 {
1230     CalendarEventPtr item = getPrivateObject(object);
1231     Try
1232     {
1233         CalendarConverter converter(context);
1234         CalendarEvent::TaskPriority priority =
1235             converter.toTaskPriority(converter.toString(value));
1236         item->setPriority(priority);
1237         return true;
1238     }
1239     Catch(Exception)
1240     {
1241                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1242     }
1243
1244     return true;
1245 }
1246
1247 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1248         JSObjectRef object,
1249         JSStringRef propertyName,
1250         JSValueRef* exception)
1251 {
1252     Try
1253     {
1254         CalendarItemPropertiesPrivObject *privateObject =
1255             static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1256         CalendarEventPtr event = privateObject->getObject();
1257         if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1258             return JSValueMakeUndefined(context);
1259         }
1260         if (!event) {
1261             ThrowMsg(NullPointerException, "Event object is NULL.");
1262         }
1263
1264         if (UNDEFINED_TIME==event->getEndTime()) {
1265             return JSValueMakeUndefined(context);
1266         } else {
1267             TimeUtilConverter timeConverter(context);
1268             return timeConverter.toJSValueRefTZDate((double)(event->getEndTime()*1000.0), event->getTimeZone());
1269         }
1270     }
1271     Catch(Exception)
1272     {
1273                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1274     }
1275     return JSValueMakeUndefined(context);
1276 }
1277
1278 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1279         JSObjectRef object,
1280         JSStringRef propertyName,
1281         JSValueRef value,
1282         JSValueRef* exception)
1283 {
1284     Try
1285     {
1286         CalendarEventPtr event = getPrivateObject(object);
1287         if (!event) {
1288             ThrowMsg(NullPointerException, "Event object is NULL.");
1289         }
1290         if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1291             ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1292         }
1293         if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1294             ThrowMsg(ConversionException, "Wrong parameter type.");
1295         }
1296
1297         TimeUtilConverter converter(context);
1298         long long int endDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1299
1300         event->setEndTime(endDate);
1301
1302         if( event->getTimeZone().empty() ) {
1303             std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1304             event->setTimeZone(timeZone);
1305         }
1306         return true;
1307     }
1308     Catch(Exception)
1309     {
1310                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1311     }
1312
1313     return true;
1314 }
1315
1316 JSValueRef JSCalendarItemProperties::getPropertyLastModificationDate(JSContextRef context,
1317         JSObjectRef object,
1318         JSStringRef propertyName,
1319         JSValueRef* exception)
1320 {
1321     Try
1322     {
1323         CalendarEventPtr item = getPrivateObject(object);
1324         if (!item) {
1325             ThrowMsg(NullPointerException, "Item object is NULL.");
1326         }
1327
1328         if (UNDEFINED_TIME==item->getLastModifiedDate()) {
1329             return JSValueMakeNull(context);
1330         } else {
1331             TimeUtilConverter timeConverter(context);
1332             return timeConverter.toJSValueRefTZDate((double)(item->getLastModifiedDate()*1000.0), item->getTimeZone());
1333         }
1334     }
1335     Catch(Exception)
1336     {
1337                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1338     }
1339     return JSValueMakeUndefined(context);
1340 }
1341
1342 JSValueRef JSCalendarItemProperties::getPropertyCalendarId(JSContextRef context,
1343         JSObjectRef object,
1344         JSStringRef propertyName,
1345         JSValueRef* exception)
1346 {
1347     Try
1348     {
1349         CalendarEventPtr item = getPrivateObject(object);
1350
1351             if (UNDEFINED_CALENDAR_ID==item->getCalendarId()) {
1352             return JSValueMakeNull(context);
1353             } else {
1354                 CalendarConverter converter(context);
1355                         std::stringstream ss;
1356                         ss<<item->getCalendarId();
1357                         return converter.toJSValueRef(ss.str());
1358             }
1359
1360     }
1361     Catch(Exception)
1362     {
1363                 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1364     }
1365     return JSValueMakeUndefined(context);
1366 }
1367
1368 }
1369 }