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