wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / TimeUtil / JSTZDate.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 <string>
20
21 #include <CommonsJavaScript/PrivateObject.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <Commons/Exception.h>
24 #include <JSTizenExceptionFactory.h>
25 #include <JSTizenException.h>
26 #include <ArgumentValidator.h>
27 #include <JSWebAPIException.h>
28
29 #include "DurationProperties.h"
30 #include "JSTZDate.h"
31 #include "TimeUtilConverter.h"
32 #include <Logger.h>
33
34 using namespace DeviceAPI::Common;
35 using namespace WrtDeviceApis::Commons;
36 using namespace WrtDeviceApis::CommonsJavaScript;
37
38 #define min(a,b) (((a) < (b)) ? (a) : (b))
39
40 #define TZDATE_ATTRIBUTENAME   "TZDate"
41
42 namespace DeviceAPI {
43 namespace Time {
44
45 JSClassDefinition JSTZDate::m_classInfo =
46 {
47     0,
48     kJSClassAttributeNone,
49     TZDATE_ATTRIBUTENAME,
50     0,
51     NULL,//property,
52     m_function,
53     initialize,
54     finalize,
55     NULL, //hasProperty,
56     NULL, //getProperty,
57     NULL, //setProperty,
58     NULL, //DeleteProperty,
59     NULL, //GetPropertyNames,
60     NULL, //CallAsFunction,
61     NULL, //CallAsConstructor,
62     NULL, //HasInstance,
63     NULL  //ConvertToType
64 };
65
66 JSStaticFunction JSTZDate::m_function[] = {
67     {"getDate",           JSTZDate::getDate,            kJSPropertyAttributeNone},
68     {"getDay",            JSTZDate::getDay,             kJSPropertyAttributeNone},
69     {"getFullYear",       JSTZDate::getFullYear,        kJSPropertyAttributeNone},
70     {"getHours",          JSTZDate::getHours,           kJSPropertyAttributeNone},
71     {"getMilliseconds",   JSTZDate::getMilliseconds,    kJSPropertyAttributeNone},
72     {"getMinutes",        JSTZDate::getMinutes,         kJSPropertyAttributeNone},
73     {"getMonth",          JSTZDate::getMonth,           kJSPropertyAttributeNone},
74     {"getSeconds",        JSTZDate::getSeconds,         kJSPropertyAttributeNone},
75
76     {"setDate",           JSTZDate::setDate,           kJSPropertyAttributeNone},
77     {"setFullYear",       JSTZDate::setFullYear,       kJSPropertyAttributeNone},
78     {"setHours",          JSTZDate::setHours,          kJSPropertyAttributeNone},
79     {"setMilliseconds",   JSTZDate::setMilliseconds,   kJSPropertyAttributeNone},
80     {"setMinutes",        JSTZDate::setMinutes,        kJSPropertyAttributeNone},
81     {"setMonth",          JSTZDate::setMonth,          kJSPropertyAttributeNone},
82     {"setSeconds",        JSTZDate::setSeconds,        kJSPropertyAttributeNone},
83
84     {"getUTCDate", JSTZDate::getUTCDate, kJSPropertyAttributeNone},
85     {"getUTCDay", JSTZDate::getUTCDay, kJSPropertyAttributeNone},
86     {"getUTCFullYear", JSTZDate::getUTCFullYear, kJSPropertyAttributeNone},
87     {"getUTCHours", JSTZDate::getUTCHours, kJSPropertyAttributeNone},
88     {"getUTCMilliseconds", JSTZDate::getUTCMilliseconds, kJSPropertyAttributeNone},
89     {"getUTCMinutes", JSTZDate::getUTCMinutes, kJSPropertyAttributeNone},
90     {"getUTCMonth", JSTZDate::getUTCMonth, kJSPropertyAttributeNone},
91     {"getUTCSeconds", JSTZDate::getUTCSeconds, kJSPropertyAttributeNone},
92
93     {"setUTCDate", JSTZDate::setUTCDate, kJSPropertyAttributeNone},
94     {"setUTCFullYear", JSTZDate::setUTCFullYear, kJSPropertyAttributeNone},
95     {"setUTCHours", JSTZDate::setUTCHours, kJSPropertyAttributeNone},
96     {"setUTCMilliseconds", JSTZDate::setUTCMilliseconds, kJSPropertyAttributeNone},
97     {"setUTCMinutes", JSTZDate::setUTCMinutes, kJSPropertyAttributeNone},
98     {"setUTCMonth", JSTZDate::setUTCMonth, kJSPropertyAttributeNone},
99     {"setUTCSeconds", JSTZDate::setUTCSeconds, kJSPropertyAttributeNone},
100
101     {"getTimezone",          JSTZDate::getTimezone,          kJSPropertyAttributeNone},
102     {"toTimezone",        JSTZDate::toTimezone,        kJSPropertyAttributeNone},
103     {"toLocalTimezone", JSTZDate::toLocalTimezone, kJSPropertyAttributeNone},
104     {"toUTC",           JSTZDate::toUTC,           kJSPropertyAttributeNone},
105
106     {"difference",         JSTZDate::difference,         kJSPropertyAttributeNone},
107     {"equalsTo",        JSTZDate::equalsTo,        kJSPropertyAttributeNone},
108     {"earlierThan",     JSTZDate::earlierThan,     kJSPropertyAttributeNone},
109     {"laterThan",       JSTZDate::laterThan,       kJSPropertyAttributeNone},
110     {"addDuration",     JSTZDate::addDuration,     kJSPropertyAttributeNone},
111
112     {"toLocaleDateString", JSTZDate::toLocaleDateString, kJSPropertyAttributeNone},
113     {"toLocaleTimeString", JSTZDate::toLocaleTimeString, kJSPropertyAttributeNone},
114     {"toLocaleString", JSTZDate::toLocaleString, kJSPropertyAttributeNone},
115     {"toDateString", JSTZDate::toDateString, kJSPropertyAttributeNone},
116     {"toTimeString", JSTZDate::toTimeString, kJSPropertyAttributeNone},
117     {"toString", JSTZDate::toString, kJSPropertyAttributeNone},
118
119     {"getTimezoneAbbreviation", JSTZDate::getTimezoneAbbreviation, kJSPropertyAttributeNone},
120     {"secondsFromUTC", JSTZDate::secondsFromUTC, kJSPropertyAttributeNone},
121     {"isDST", JSTZDate::isDST, kJSPropertyAttributeNone},
122     {"getPreviousDSTTransition", JSTZDate::getPreviousDSTTransition, kJSPropertyAttributeNone},
123     {"getNextDSTTransition", JSTZDate::getNextDSTTransition, kJSPropertyAttributeNone},
124     { 0, 0, 0}
125 };
126
127 JSClassRef JSTZDate::m_jsClassRef = JSClassCreate(JSTZDate::getClassInfo());
128
129 JSObjectRef JSTZDate::createJSObject(JSContextRef context) {
130         LoggerD("entered");
131         TZDatePtr tzDate(new TZDate());
132         TZDatePrivObject *priv = new TZDatePrivObject(context, tzDate);
133         if (!priv) {
134                 ThrowMsg(NullPointerException, "Can not new an object");
135         }
136
137         return JSObjectMake(context, getClassRef(), priv);
138 }
139
140 JSObjectRef JSTZDate::createJSObject(JSContextRef context, const std::string &timezone) {
141         LoggerD("entered");
142         if (timezone == "")
143                 return createJSObject(context);
144
145         TZDatePtr tzDate(new TZDate(timezone));
146         TZDatePrivObject *priv = new TZDatePrivObject(context, tzDate);
147         if (!priv) {
148                 ThrowMsg(NullPointerException, "Can not new an object");
149         }
150
151         return JSObjectMake(context, getClassRef(), priv);
152 }
153
154 JSObjectRef JSTZDate::createJSObject(JSContextRef context, const double milliseconds, const std::string &timezone) {
155         LoggerD("entered");
156         TZDatePtr tzDate;
157         if (timezone == "")
158                 tzDate = TZDatePtr(new TZDate());
159         else
160                 tzDate = TZDatePtr(new TZDate(timezone));
161
162         if (!tzDate->setTime(milliseconds))
163                 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Can not set UTC Time");
164
165         TZDatePrivObject *priv = new TZDatePrivObject(context, tzDate);
166         if (!priv) {
167                 ThrowMsg(NullPointerException, "Can not new an object");
168         }
169
170         return JSObjectMake(context, getClassRef(), priv);
171 }
172
173 JSObjectRef JSTZDate::createJSObject(JSContextRef context, const TZDateProperties &properties) {
174         LoggerD("entered");
175         TZDatePtr tzDate(new TZDate(properties));
176
177         TZDatePrivObject *priv = new TZDatePrivObject(context, tzDate);
178         if (!priv) {
179                 ThrowMsg(NullPointerException, "Can not new an object");
180         }
181
182         return JSObjectMake(context, getClassRef(), priv);
183 }
184
185 JSObjectRef JSTZDate::createJSObject(JSContextRef context, const long year, const long month,  const long day, const long hours, const long minutes, const long seconds, const long milliseconds, const std::string &timezone) {
186         LoggerD("entered");
187
188         TZDateProperties props;
189         props.year = year;
190         props.month = month;
191         props.day = day;
192         props.hours = hours;
193         props.minutes = minutes;
194         props.seconds = seconds;
195         props.milliseconds = milliseconds;
196         props.timezone = timezone;
197
198         return createJSObject(context, props);
199
200 }
201
202 void JSTZDate::initialize(JSContextRef context, JSObjectRef object)
203 {
204         LoggerD("entered Nothing to do.");
205 }
206
207 void JSTZDate::finalize(JSObjectRef object)
208 {
209     LoggerD( "entered" );
210     TZDatePrivObject *priv =
211         static_cast<TZDatePrivObject*>( JSObjectGetPrivate( object ) ) ;
212     delete priv;
213 }
214
215 JSObjectRef JSTZDate::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
216 {
217         LoggerD("entered");
218         TZDateProperties prop;
219         TimeUtilConverter converter(ctx);
220
221         Try {
222                 JSObjectRef tzDate = NULL;
223
224                 if (argumentCount == 0) {
225                         tzDate = createJSObject(ctx);
226                 } else if (argumentCount <= 2) {
227                         std::string timezone = "";
228                         if ((argumentCount == 2) && !JSValueIsNull(ctx, arguments[1]) && !JSValueIsUndefined(ctx, arguments[1])) {
229                                 timezone = converter.toString(arguments[1]);
230                         }
231
232                         if (JSValueIsNull(ctx, arguments[0]) || JSValueIsUndefined(ctx, arguments[0])) {
233                                 tzDate = createJSObject(ctx, timezone);
234                         } else {
235                                 struct tm date = converter.toDateTm(arguments[0]);
236                                 LoggerD("date = " << date.tm_year << "." << date.tm_mon << "." << date.tm_mday);
237                                 LoggerD(date.tm_hour << ":" << date.tm_min << ":" << date.tm_sec);
238                                 LoggerD("isdst?" << date.tm_isdst);
239
240                                 prop.timezone = timezone;
241                                 prop.year = date.tm_year + 1900;
242                                 prop.month = date.tm_mon;
243                                 prop.day = date.tm_mday;
244                                 prop.hours = date.tm_hour;
245                                 prop.minutes = date.tm_min;
246                                 prop.seconds = date.tm_sec;
247
248                             JSStringRef getMillisecondsName = JSStringCreateWithUTF8CString("getMilliseconds");
249                                 JSValueRef getMiliSecFuction = JSObjectGetProperty(ctx, converter.toJSObjectRef(arguments[0]), getMillisecondsName, exception);
250                                 JSStringRelease(getMillisecondsName);
251                                 if (getMiliSecFuction) {
252                                         JSObjectRef function = JSValueToObject(ctx, getMiliSecFuction, exception);
253                                         JSValueRef result = JSObjectCallAsFunction(ctx, function, converter.toJSObjectRef(arguments[0]), 0, NULL, exception);
254                                         prop.milliseconds = converter.toLong(result);
255                                         LoggerD("getMilliseconds = " << prop.milliseconds);
256                                 }
257                                 tzDate = createJSObject(ctx, prop);
258                         }
259                 } else {
260                         prop.year = converter.toLong(arguments[0]);
261                         if ((prop.year >= 0) && (prop.year <= 99))
262                                 prop.year += 1900;
263                         prop.month = converter.toLong(arguments[1]);
264                         prop.day = converter.toLong(arguments[2]);
265                         if (argumentCount > 3) {
266                                 if (!JSValueIsUndefined(ctx, arguments[3]) && !JSValueIsNull(ctx, arguments[3]))
267                                         prop.hours = converter.toLong(arguments[3]);
268                                 if (argumentCount > 4) {
269                                         if (!JSValueIsUndefined(ctx, arguments[4]) && !JSValueIsNull(ctx, arguments[4]))
270                                                 prop.minutes = converter.toLong(arguments[4]);
271                                         if (argumentCount > 5) {
272                                                 if (!JSValueIsUndefined(ctx, arguments[5]) && !JSValueIsNull(ctx, arguments[5]))
273                                                         prop.seconds = converter.toLong(arguments[5]);
274                                                 if (argumentCount > 6) {
275                                                         if (!JSValueIsUndefined(ctx, arguments[6]) && !JSValueIsNull(ctx, arguments[6]))
276                                                                 prop.milliseconds= converter.toLong(arguments[6]);
277                                                         if (argumentCount > 7) {
278                                                                 if (!JSValueIsUndefined(ctx, arguments[7]) && !JSValueIsNull(ctx, arguments[7]))
279                                                                         prop.timezone = converter.toString(arguments[7]);
280                                                         }
281                                                 }
282                                         }
283                                 }
284                         }
285                         tzDate = createJSObject(ctx, prop);
286                 }
287
288                 if (tzDate) {
289                         JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
290                     JSObjectSetProperty(ctx, tzDate, ctorName, constructor,
291                         kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
292                 JSStringRelease(ctorName);
293                         return tzDate;
294                 }
295         } Catch(ConversionException) {
296                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
297                 JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
298                 *exception = error;
299                 return error;
300         } Catch (InvalidArgumentException) {
301                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
302                 JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
303                 *exception = error;
304                 return error;
305         } Catch (PlatformException) {
306                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
307         } Catch (WrtDeviceApis::Commons::Exception) {
308                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
309         }
310         JSObjectRef error = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
311         *exception = error;
312         return error;
313 }
314 const JSClassRef JSTZDate::getClassRef()
315 {
316     if (!m_jsClassRef) {
317             m_jsClassRef = JSClassCreate(&m_classInfo);
318     }
319     return m_jsClassRef;
320 }
321
322 const JSClassDefinition* JSTZDate::getClassInfo()
323 {
324     return &m_classInfo;
325 }
326
327 JSValueRef JSTZDate::getTimezone(JSContextRef context, JSObjectRef function,
328         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
329         LoggerD("entered");
330
331         Try {
332                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
333                 if (!privateObject) {
334                         LoggerE("Private object is not set.");
335                         ThrowMsg(NullPointerException, "Private object not initialized");
336                 }
337
338                 TZDatePtr tzDate(privateObject->getObject());
339                 std::string timezone = tzDate->getTimezone();
340                 TimeUtilConverter converter(context);
341
342                 return converter.toJSValueRef(timezone);
343         } Catch(NullPointerException) {
344                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
345                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
346         } Catch(WrtDeviceApis::Commons::UnknownException) {
347                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
348         } Catch (InvalidArgumentException) {
349                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
350                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
351         } Catch (PlatformException) {
352                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
353         }
354
355         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
356 }
357
358 JSValueRef JSTZDate::toTimezone(JSContextRef context, JSObjectRef function,
359         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
360         LoggerD("entered");
361
362         try {
363                 ArgumentValidator validator(context, argumentCount, arguments);
364                 std::string timezone = validator.toString(0);
365
366                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
367                 if (!privateObject) {
368                         LoggerE("Private object is not set.");
369                         ThrowMsg(NullPointerException, "Private object not initialized");
370                 }
371
372                 TZDatePtr tzDate(privateObject->getObject());
373                 return createJSObject(context, tzDate->getTime(), timezone);
374         } catch(const BasePlatformException& err){
375         return JSWebAPIException::throwException(context, exception, err);
376     } Catch(NullPointerException) {
377                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
378                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
379         } Catch(WrtDeviceApis::Commons::UnknownException) {
380                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
381         } Catch (InvalidArgumentException) {
382                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
383                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
384         } Catch(ConversionException) {
385                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
386                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
387         } Catch (PlatformException) {
388                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
389         }
390
391         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
392 }
393
394 JSValueRef JSTZDate::diffTZDate(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception, CompareType type) {
395         LoggerD("entered");
396
397         ArgumentValidator validator(context, argumentCount, arguments);
398         if (!validator.toObject(0, JSTZDate::getClassRef(), false))
399                 ThrowMsg(ConversionException, "Parameter is not TZDate");
400
401         TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
402         if (!privateObject) {
403                 LoggerE("Private object is not set.");
404                 ThrowMsg(NullPointerException, "Private object not initialized");
405         }
406         TimeUtilConverter converter(context);
407         TZDatePtr tzDate(privateObject->getObject());
408         long long cmpResult = tzDate->difference(converter.getPropertiesInTZDate(arguments[0]));
409
410         switch (type) {
411                 case EQUALSTO:
412                 {
413                         if (cmpResult == 0)
414                                 return converter.toJSValueRef(true);
415                         else
416                                 return converter.toJSValueRef(false);
417                 }
418                 case EARLIERTHAN:
419                 {
420                         if (cmpResult < 0)
421                                 return converter.toJSValueRef(true);
422                         else
423                                 return converter.toJSValueRef(false);
424                 }
425                 case LATERTHAN:
426                 {
427                         if (cmpResult > 0)
428                                 return converter.toJSValueRef(true);
429                         else
430                                 return converter.toJSValueRef(false);
431                 }
432                 case DIFFERENCE:
433                 default:
434                         return converter.makeMillisecondDurationObject(cmpResult);
435         }
436 }
437
438 JSValueRef JSTZDate::difference(JSContextRef context, JSObjectRef function,
439         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
440         LoggerD("entered");
441
442         Try {
443                 return diffTZDate(context, thisObject, argumentCount,  arguments, exception, DIFFERENCE);
444         } catch(const BasePlatformException& err){
445         return JSWebAPIException::throwException(context, exception, err);
446     } Catch(InvalidArgumentException) {
447                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
448                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
449         } Catch(NullPointerException) {
450                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
451                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
452         } Catch(WrtDeviceApis::Commons::UnknownException) {
453                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
454         } Catch(ConversionException) {
455                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
456                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
457         } Catch (PlatformException) {
458                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
459         }
460
461         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
462 }
463
464 JSValueRef JSTZDate::equalsTo(JSContextRef context, JSObjectRef function,
465         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
466         LoggerD("entered");
467
468         Try {
469                 return diffTZDate(context, thisObject, argumentCount,  arguments, exception, EQUALSTO);
470         } catch(const BasePlatformException& err){
471         return JSWebAPIException::throwException(context, exception, err);
472     } Catch(NullPointerException) {
473                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
474                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
475         } Catch(WrtDeviceApis::Commons::UnknownException) {
476                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
477         } Catch (InvalidArgumentException) {
478                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
479                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
480         } Catch(ConversionException) {
481                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
482                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
483         } Catch (PlatformException) {
484                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
485         }
486         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
487 }
488
489 JSValueRef JSTZDate::earlierThan(JSContextRef context, JSObjectRef function,
490         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
491         LoggerD("earlierThan entered");
492
493         Try {
494                 return diffTZDate(context, thisObject, argumentCount,  arguments, exception, EARLIERTHAN);
495         } catch(const BasePlatformException& err){
496         return JSWebAPIException::throwException(context, exception, err);
497     } Catch(NullPointerException) {
498                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
499                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
500         } Catch(WrtDeviceApis::Commons::UnknownException) {
501                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
502         } Catch (InvalidArgumentException) {
503                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
504                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
505         } Catch(ConversionException) {
506                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
507                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
508         } Catch (PlatformException) {
509                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
510         }
511         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
512
513 }
514
515 JSValueRef JSTZDate::laterThan(JSContextRef context, JSObjectRef function,
516         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
517
518         LoggerD("laterThan entered");
519
520         Try {
521                 return diffTZDate(context, thisObject, argumentCount,  arguments, exception, LATERTHAN);
522         } catch(const BasePlatformException& err){
523         return JSWebAPIException::throwException(context, exception, err);
524     } Catch(NullPointerException) {
525                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
526                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
527         } Catch(WrtDeviceApis::Commons::UnknownException) {
528                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
529         } Catch (InvalidArgumentException) {
530                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
531                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
532         } Catch(ConversionException) {
533                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
534                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
535         } Catch (PlatformException) {
536                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
537         }
538         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
539
540 }
541
542 JSValueRef JSTZDate::addDuration(JSContextRef context, JSObjectRef function,
543         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
544
545         LoggerD("addDuration entered");
546         Try {
547                 TimeUtilConverter converter(context);
548
549                 DurationProperties duration;
550                 if (argumentCount == 0)
551                         duration= converter.getDurationPropertis(JSValueMakeUndefined(context));
552                 else
553                         duration= converter.getDurationPropertis(arguments[0]);
554
555                 LoggerD("unit : " << duration.unit << " Length:" << duration.length);
556                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
557                 if (!privateObject) {
558                         LoggerE("Private object is not set.");
559                         ThrowMsg(NullPointerException, "Private object not initialized");
560                 }
561
562                 TZDatePtr tzDate(privateObject->getObject());
563                 TZDateProperties result = tzDate->addDuration(duration);
564
565                 return (static_cast<JSValueRef>(createJSObject(context, result)));
566         } Catch(NullPointerException) {
567                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
568                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
569         } Catch(WrtDeviceApis::Commons::UnknownException) {
570                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
571         } Catch (InvalidArgumentException) {
572                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
573                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
574         } Catch(ConversionException) {
575                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
576                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
577         } Catch (PlatformException) {
578                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
579         } Catch (OutOfRangeException) {
580                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
581                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "The result is beyond the scope that TZDate can handle.");
582         }
583
584         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
585 }
586
587 JSValueRef JSTZDate::toUTC(JSContextRef context, JSObjectRef function,
588         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
589
590         LoggerD("toUTC entered");
591         Try {
592                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
593                 if (!privateObject) {
594                         LoggerE("Private object is not set.");
595                         ThrowMsg(NullPointerException, "Private object not initialized");
596                 }
597
598                 TZDatePtr tzDate(privateObject->getObject());
599                 return createJSObject(context, tzDate->getTime(), tzDate->getUTCTimezoneName());
600         } Catch(NullPointerException) {
601                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
602                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
603         } Catch(WrtDeviceApis::Commons::UnknownException) {
604                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
605         } Catch (InvalidArgumentException) {
606                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
607                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
608         } Catch (PlatformException) {
609                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
610         }
611         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
612 }
613
614
615 JSValueRef JSTZDate::toLocalTimezone(JSContextRef context, JSObjectRef function,
616         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
617
618         LoggerD("toLocalTimezone entered");
619         Try {
620                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
621                 if (!privateObject) {
622                         LoggerE("Private object is not set.");
623                         ThrowMsg(NullPointerException, "Private object not initialized");
624                 }
625
626                 TZDatePtr tzDate(privateObject->getObject());
627                 return createJSObject(context, tzDate->getTime(), tzDate->getLocalTimezoneName());
628         } Catch(NullPointerException) {
629                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
630                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
631         } Catch(WrtDeviceApis::Commons::UnknownException) {
632                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
633         } Catch (InvalidArgumentException) {
634                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
635                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
636         } Catch (PlatformException) {
637                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
638         }
639         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
640 }
641
642 JSValueRef JSTZDate::toLocaleDateString(JSContextRef context, JSObjectRef function,
643         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
644         LoggerD("Entered");
645         Try {
646                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
647                 if (!privateObject) {
648                         LoggerE("Private object is not set.");
649                         ThrowMsg(NullPointerException, "Private object not initialized");
650                 }
651
652                 TimeUtilConverter converter(context);
653
654                 TZDatePtr tzDate(privateObject->getObject());
655                 std::string result = tzDate->toDateString(true);
656                 return converter.toJSValueRef(result);
657         } Catch(NullPointerException) {
658                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
659                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
660         } Catch(WrtDeviceApis::Commons::UnknownException) {
661                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
662         } Catch (InvalidArgumentException) {
663                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
664                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
665         } Catch (PlatformException) {
666                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
667         }
668
669         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
670 }
671
672 JSValueRef JSTZDate::toLocaleTimeString(JSContextRef context, JSObjectRef function,
673         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
674         LoggerD("Entered");
675         Try {
676                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
677                 if (!privateObject) {
678                         LoggerE("Private object is not set.");
679                         ThrowMsg(NullPointerException, "Private object not initialized");
680                 }
681
682                 TimeUtilConverter converter(context);
683
684                 TZDatePtr tzDate(privateObject->getObject());
685                 std::string result = tzDate->toTimeString(true);
686                 return converter.toJSValueRef(result);
687         } Catch(NullPointerException) {
688                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
689                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
690         } Catch(WrtDeviceApis::Commons::UnknownException) {
691                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
692         } Catch (InvalidArgumentException) {
693                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
694                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
695         } Catch (PlatformException) {
696                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
697         }
698
699         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
700 }
701
702 JSValueRef JSTZDate::toLocaleString(JSContextRef context, JSObjectRef function,
703         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
704         LoggerD("Entered");
705         Try {
706                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
707                 if (!privateObject) {
708                         LoggerE("Private object is not set.");
709                         ThrowMsg(NullPointerException, "Private object not initialized");
710                 }
711
712                 TimeUtilConverter converter(context);
713
714                 TZDatePtr tzDate(privateObject->getObject());
715                 std::string result = tzDate->toString(true);
716                 return converter.toJSValueRef(result);
717         } Catch(NullPointerException) {
718                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
719                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
720         } Catch(WrtDeviceApis::Commons::UnknownException) {
721                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
722         } Catch (InvalidArgumentException) {
723                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
724                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
725         } Catch (PlatformException) {
726                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
727         }
728
729         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
730 }
731
732 JSValueRef JSTZDate::toDateString(JSContextRef context, JSObjectRef function,
733         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
734         LoggerD("Entered");
735         Try {
736                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
737                 if (!privateObject) {
738                         LoggerE("Private object is not set.");
739                         ThrowMsg(NullPointerException, "Private object not initialized");
740                 }
741
742                 TimeUtilConverter converter(context);
743
744                 TZDatePtr tzDate(privateObject->getObject());
745                 std::string result = tzDate->toDateString();
746                 return converter.toJSValueRef(result);
747         } Catch(NullPointerException) {
748                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
749                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
750         } Catch(WrtDeviceApis::Commons::UnknownException) {
751                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
752         } Catch (InvalidArgumentException) {
753                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
754                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
755         } Catch (PlatformException) {
756                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
757         }
758
759         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
760 }
761
762 JSValueRef JSTZDate::toTimeString(JSContextRef context, JSObjectRef function,
763         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
764         LoggerD("Entered");
765         Try {
766                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
767                 if (!privateObject) {
768                         LoggerE("Private object is not set.");
769                         ThrowMsg(NullPointerException, "Private object not initialized");
770                 }
771
772                 TimeUtilConverter converter(context);
773
774                 TZDatePtr tzDate(privateObject->getObject());
775                 std::string result = tzDate->toTimeString();
776                 return converter.toJSValueRef(result);
777         } Catch(NullPointerException) {
778                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
779                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
780         } Catch(WrtDeviceApis::Commons::UnknownException) {
781                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
782         } Catch (InvalidArgumentException) {
783                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
784                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
785         } Catch (PlatformException) {
786                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
787         }
788
789         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
790 }
791
792
793 JSValueRef JSTZDate::toString(JSContextRef context, JSObjectRef function,
794         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
795         LoggerD("Entered");
796         Try {
797                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
798                 if (!privateObject) {
799                         LoggerE("Private object is not set.");
800                         ThrowMsg(NullPointerException, "Private object not initialized");
801                 }
802
803                 TimeUtilConverter converter(context);
804
805                 TZDatePtr tzDate(privateObject->getObject());
806                 std::string result = tzDate->toString();
807                 return converter.toJSValueRef(result);
808         } Catch(NullPointerException) {
809                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
810                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
811         } Catch(WrtDeviceApis::Commons::UnknownException) {
812                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
813         } Catch (InvalidArgumentException) {
814                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
815                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
816         } Catch (PlatformException) {
817                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
818         }
819
820         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
821 }
822
823 JSValueRef JSTZDate::getDate(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
824         JSValueRef * exception) {
825         LoggerD("<<<");
826
827         TZDate::TZDateFields dateFields = TZDate::TZDATE_DATE;
828         return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
829 } //getDate()
830
831 JSValueRef JSTZDate::getDay(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
832         JSValueRef * exception) {
833         LoggerD("<<<");
834
835         TZDate::TZDateFields dateFields = TZDate::TZDATE_DAY_OF_WEEK;
836         return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
837 } //getDay()
838
839 JSValueRef JSTZDate::getFullYear(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
840         JSValueRef * exception) {
841         LoggerD("<<<");
842
843         TZDate::TZDateFields dateFields = TZDate::TZDATE_YEAR;
844         return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
845 } //getFullYear()
846
847 JSValueRef JSTZDate::getHours(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
848         JSValueRef * exception) {
849         LoggerD("<<<");
850
851         TZDate::TZDateFields dateFields = TZDate::TZDATE_HOUR_OF_DAY;
852         return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
853 } //getHours()
854
855 JSValueRef JSTZDate::getMilliseconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
856         JSValueRef * exception) {
857         LoggerD("<<<");
858
859         TZDate::TZDateFields dateFields = TZDate::TZDATE_MILLISECOND;
860         return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
861 } //getMilliseconds()
862
863 JSValueRef JSTZDate::getMinutes(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
864         JSValueRef * exception) {
865         LoggerD("<<<");
866
867         TZDate::TZDateFields dateFields = TZDate::TZDATE_MINUTE;
868         return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
869 } //getMinutes()
870
871 JSValueRef JSTZDate::getMonth(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
872         JSValueRef * exception) {
873         LoggerD("<<<");
874         TZDate::TZDateFields dateFields = TZDate::TZDATE_MONTH;
875         return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
876 } //getMonth()
877
878 JSValueRef JSTZDate::getSeconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
879         JSValueRef * exception) {
880         LoggerD("<<<");
881
882         TZDate::TZDateFields dateFields = TZDate::TZDATE_SECOND;
883         return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
884 } //getSeconds()
885
886 JSValueRef JSTZDate::getTZDateValue(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception,
887         TZDate::TZDateFields dateFields) {
888         try {
889                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*> (JSObjectGetPrivate(thisObject));
890
891                 if (privateObject == NULL) {
892                         LoggerE(">>> NULL Exception");
893                         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
894                 }
895
896                 TZDatePtr tzDate(privateObject->getObject());
897                 long retVal = tzDate->get(dateFields);
898
899                 TimeUtilConverter converter(context);
900                 LoggerD(">>> retVal:" << retVal);
901                 return converter.toJSValueRef(static_cast<int> (retVal));
902         } Catch(NullPointerException) {
903                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
904                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
905         } Catch(WrtDeviceApis::Commons::UnknownException) {
906                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
907         } Catch (InvalidArgumentException) {
908                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
909                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
910         } Catch (PlatformException) {
911                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
912         }
913
914         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
915 }
916
917 JSValueRef JSTZDate::setDate(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
918         JSValueRef * exception) {
919         LoggerD("<<<");
920
921         TZDate::TZDateFields dateFields = TZDate::TZDATE_DATE;
922
923         try{
924                 setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
925         } catch(const BasePlatformException& err){
926         return JSWebAPIException::throwException(context, exception, err);
927     }   Catch(NullPointerException) {
928                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
929                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
930         } Catch(WrtDeviceApis::Commons::UnknownException) {
931                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
932                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
933         } Catch (InvalidArgumentException) {
934                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
935                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
936         } Catch(ConversionException) {
937                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
938                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
939         } Catch (PlatformException) {
940                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
941                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
942         }
943
944         return JSValueMakeNull(context);
945 } //setDate()
946
947 JSValueRef JSTZDate::setFullYear(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
948         JSValueRef * exception) {
949         LoggerD("<<<");
950
951         TZDate::TZDateFields dateFields = TZDate::TZDATE_YEAR;
952
953         try{
954                 setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
955         } catch(const BasePlatformException& err){
956         return JSWebAPIException::throwException(context, exception, err);
957     } Catch(NullPointerException) {
958                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
959                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
960         } Catch(WrtDeviceApis::Commons::UnknownException) {
961                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
962                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
963         } Catch (InvalidArgumentException) {
964                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
965                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
966         } Catch(ConversionException) {
967                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
968                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
969         } Catch (PlatformException) {
970                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
971                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
972         }
973
974         return JSValueMakeNull(context);
975 } //setFullYear()
976
977 JSValueRef JSTZDate::setHours(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
978         JSValueRef * exception) {
979         LoggerD("<<<");
980
981         TZDate::TZDateFields dateFields = TZDate::TZDATE_HOUR_OF_DAY;
982
983         Try {
984                 setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
985         } catch(const BasePlatformException& err){
986         return JSWebAPIException::throwException(context, exception, err);
987     }Catch(NullPointerException) {
988                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
989                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
990         } Catch(WrtDeviceApis::Commons::UnknownException) {
991                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
992                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
993         } Catch (InvalidArgumentException) {
994                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
995                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
996         } Catch(ConversionException) {
997                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
998                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
999         } Catch (PlatformException) {
1000                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1001                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1002         }
1003
1004         return JSValueMakeNull(context);
1005 } //setHours()
1006
1007 JSValueRef JSTZDate::setMilliseconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
1008         JSValueRef * exception) {
1009         LoggerD("<<<");
1010
1011         TZDate::TZDateFields dateFields = TZDate::TZDATE_MILLISECOND;
1012         
1013         Try{
1014                 setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
1015         } catch(const BasePlatformException& err){
1016         return JSWebAPIException::throwException(context, exception, err);
1017     }Catch(NullPointerException) {
1018                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1019                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1020         } Catch(WrtDeviceApis::Commons::UnknownException) {
1021                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1022                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1023         } Catch (InvalidArgumentException) {
1024                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1025                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
1026         } Catch(ConversionException) {
1027                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1028                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1029         } Catch (PlatformException) {
1030                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1031                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1032         }
1033
1034         return JSValueMakeNull(context);
1035 } //setMilliseconds()
1036
1037 JSValueRef JSTZDate::setMinutes(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
1038         JSValueRef * exception) {
1039         LoggerD("<<<");
1040
1041         TZDate::TZDateFields dateFields = TZDate::TZDATE_MINUTE;
1042
1043         Try {
1044                 setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
1045         } catch(const BasePlatformException& err){
1046         return JSWebAPIException::throwException(context, exception, err);
1047     }Catch(NullPointerException) {
1048                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1049                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1050         } Catch(WrtDeviceApis::Commons::UnknownException) {
1051                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1052                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1053         } Catch (InvalidArgumentException) {
1054                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1055                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
1056         } Catch(ConversionException) {
1057                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1058                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1059         } Catch (PlatformException) {
1060                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1061                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1062         }
1063
1064         return JSValueMakeNull(context);
1065 } //setMinutes()
1066
1067 JSValueRef JSTZDate::setMonth(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
1068         JSValueRef * exception) {
1069         LoggerD("<<<");
1070
1071         TZDate::TZDateFields dateFields = TZDate::TZDATE_MONTH;
1072
1073         Try {
1074                 setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
1075         } catch(const BasePlatformException& err){
1076         return JSWebAPIException::throwException(context, exception, err);
1077     }Catch(NullPointerException) {
1078                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1079                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1080         } Catch(WrtDeviceApis::Commons::UnknownException) {
1081                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1082                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1083         } Catch (InvalidArgumentException) {
1084                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1085                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
1086         } Catch(ConversionException) {
1087                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1088                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1089         } Catch (PlatformException) {
1090                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1091                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1092         }
1093
1094         return JSValueMakeNull(context);
1095 } //setMonth()
1096
1097 JSValueRef JSTZDate::setSeconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
1098         JSValueRef * exception) {
1099         LoggerD("<<<");
1100
1101         TZDate::TZDateFields dateFields = TZDate::TZDATE_SECOND;
1102
1103         Try {
1104                 setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
1105         } catch(const BasePlatformException& err){
1106         return JSWebAPIException::throwException(context, exception, err);
1107     }Catch(NullPointerException) {
1108                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1109                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1110         } Catch(WrtDeviceApis::Commons::UnknownException) {
1111                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1112                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1113         } Catch (InvalidArgumentException) {
1114                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1115                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
1116         } Catch(ConversionException) {
1117                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1118                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1119         } Catch (PlatformException) {
1120                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1121                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1122         }
1123
1124         return JSValueMakeNull(context);
1125 } //setSeconds()
1126
1127
1128 JSValueRef JSTZDate::setTZDateValue(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
1129         JSValueRef * exception, TZDate::TZDateFields dateFields) {
1130         ArgumentValidator validator(context, argumentCount, arguments);
1131         long data = validator.toLong(0);
1132
1133         if ((dateFields == TZDate::TZDATE_YEAR) && (data < 0))
1134                 ThrowMsg(InvalidArgumentException, "Invalid Argument:Year can't be set to negative");
1135
1136         TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*> (JSObjectGetPrivate(thisObject));
1137
1138         if (privateObject == NULL) {
1139                 LoggerE(">>> NULL Exception");
1140                 ThrowMsg(NullPointerException, "privateObject is NULL");
1141         }
1142
1143         TZDatePtr tzDate(privateObject->getObject());
1144         tzDate->set(dateFields,data);
1145
1146         return JSValueMakeNull(context);
1147 }       //setTZDateValue
1148
1149 JSValueRef JSTZDate::getUTCDate(JSContextRef context, JSObjectRef function,
1150         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1151         LoggerD("Entered");
1152         return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_DATE, exception);
1153 }
1154
1155 JSValueRef JSTZDate::getUTCDay(JSContextRef context, JSObjectRef function,
1156         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1157         LoggerD("Entered");
1158         return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_DAY_OF_WEEK, exception);
1159 }
1160
1161 JSValueRef JSTZDate::getUTCFullYear(JSContextRef context, JSObjectRef function,
1162         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1163         LoggerD("Entered");
1164         return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_YEAR, exception);
1165 }
1166
1167 JSValueRef JSTZDate::getUTCHours(JSContextRef context, JSObjectRef function,
1168         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1169         LoggerD("Entered");
1170         return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_HOUR_OF_DAY, exception);
1171 }
1172
1173 JSValueRef JSTZDate::getUTCMilliseconds(JSContextRef context, JSObjectRef function,
1174         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1175         LoggerD("Entered");
1176         return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_MILLISECOND, exception);
1177 }
1178
1179 JSValueRef JSTZDate::getUTCMinutes(JSContextRef context, JSObjectRef function,
1180         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1181         LoggerD("Entered");
1182         return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_MINUTE, exception);
1183 }
1184
1185 JSValueRef JSTZDate::getUTCMonth(JSContextRef context, JSObjectRef function,
1186         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1187         LoggerD("Entered");
1188         return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_MONTH, exception);
1189 }
1190
1191 JSValueRef JSTZDate::getUTCSeconds(JSContextRef context, JSObjectRef function,
1192         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1193         LoggerD("Entered");
1194         return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_SECOND, exception);
1195 }
1196
1197 JSValueRef JSTZDate::getUTCTZDateValue(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, TZDate::TZDateFields DateFields, JSValueRef * exception) {
1198         LoggerD("Entered");
1199         Try {
1200                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
1201                 if (!privateObject) {
1202                         LoggerE("Private object is not set.");
1203                         ThrowMsg(NullPointerException, "Private object not initialized");
1204                 }
1205
1206                 TimeUtilConverter converter(context);
1207
1208                 TZDatePtr tzDate(privateObject->getObject());
1209                 long result = tzDate->getUTC(DateFields);
1210
1211                 return converter.toJSValueRefLong(result);
1212         } Catch(NullPointerException) {
1213                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1214                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1215         } Catch(WrtDeviceApis::Commons::UnknownException) {
1216                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1217         } Catch (InvalidArgumentException) {
1218                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1219                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
1220         } Catch (PlatformException) {
1221                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1222         }
1223
1224         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1225 }
1226
1227 JSValueRef JSTZDate::setUTCDate(JSContextRef context, JSObjectRef function,
1228         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1229         LoggerD("Entered");
1230
1231         return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_DATE, exception);
1232 }
1233
1234 JSValueRef JSTZDate::setUTCFullYear(JSContextRef context, JSObjectRef function,
1235         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1236         LoggerD("Entered");
1237
1238         return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_YEAR, exception);
1239 }
1240
1241 JSValueRef JSTZDate::setUTCHours(JSContextRef context, JSObjectRef function,
1242         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1243         LoggerD("Entered");
1244
1245         return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_HOUR_OF_DAY, exception);
1246 }
1247
1248 JSValueRef JSTZDate::setUTCMilliseconds(JSContextRef context, JSObjectRef function,
1249         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1250         LoggerD("Entered");
1251
1252         return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_MILLISECOND, exception);
1253 }
1254
1255 JSValueRef JSTZDate::setUTCMinutes(JSContextRef context, JSObjectRef function,
1256         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1257         LoggerD("Entered");
1258
1259         return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_MINUTE, exception);
1260 }
1261
1262 JSValueRef JSTZDate::setUTCMonth(JSContextRef context, JSObjectRef function,
1263         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1264         LoggerD("Entered");
1265
1266         return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_MONTH, exception);
1267 }
1268
1269 JSValueRef JSTZDate::setUTCSeconds(JSContextRef context, JSObjectRef function,
1270         JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1271         LoggerD("Entered");
1272
1273         return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_SECOND, exception);
1274 }
1275
1276 JSValueRef JSTZDate::setUTCTZDateValue(JSContextRef context, JSObjectRef thisObject,
1277         size_t argumentCount, const JSValueRef arguments[], TZDate::TZDateFields dateFields, JSValueRef * exception) {
1278         LoggerD("Entered");
1279         Try {
1280                 TimeUtilConverter converter(context);
1281                 
1282                 long data = 0;
1283                 if (argumentCount == 0)
1284                         data = converter.toLong(JSValueMakeUndefined(context));
1285                 else
1286                         data = converter.toLong(arguments[0]);
1287
1288                 if ((dateFields == TZDate::TZDATE_YEAR) && (data < 0))
1289                         ThrowMsg(InvalidArgumentException, "Invalid Argument:Year can't be set to negative");
1290
1291                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
1292                 if (!privateObject) {
1293                         LoggerE("Private object is not set.");
1294                         ThrowMsg(NullPointerException, "Private object not initialized");
1295                 }
1296
1297                 TZDatePtr tzDate(privateObject->getObject());
1298                 tzDate->setUTC(dateFields, data);
1299
1300                 return JSValueMakeNull(context);
1301         } Catch(NullPointerException) {
1302                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1303                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1304         } Catch(WrtDeviceApis::Commons::UnknownException) {
1305                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1306         } Catch (InvalidArgumentException) {
1307                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1308                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
1309         } Catch(ConversionException) {
1310                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1311                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1312         } Catch (PlatformException) {
1313                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1314         }
1315
1316         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1317 }
1318
1319 JSValueRef JSTZDate::getTimezoneAbbreviation(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1320         LoggerD("entered");
1321         Try {
1322                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
1323                 if (!privateObject) {
1324                         LoggerE("Private object is not set.");
1325                         ThrowMsg(NullPointerException, "Private object not initialized");
1326                 }
1327
1328                 TimeUtilConverter converter(context);
1329
1330                 TZDatePtr tzDate(privateObject->getObject());
1331
1332                 std::string result;
1333
1334                 return converter.toJSValueRef(tzDate->getTimezoneAbbreviation());
1335         } Catch(NullPointerException) {
1336                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1337                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1338         } Catch(WrtDeviceApis::Commons::UnknownException) {
1339                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1340         } Catch (InvalidArgumentException) {
1341                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1342                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
1343         } Catch (PlatformException) {
1344                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1345         }
1346         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1347 }
1348
1349 JSValueRef JSTZDate::secondsFromUTC(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1350         LoggerD("entered");
1351
1352         Try {
1353                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
1354                 if (!privateObject) {
1355                         LoggerE("Private object is not set.");
1356                         ThrowMsg(NullPointerException, "Private object not initialized");
1357                 }
1358
1359                 TimeUtilConverter converter(context);
1360
1361                 TZDatePtr tzDate(privateObject->getObject());
1362
1363                 return converter.toJSValueRefLong(tzDate->secondsFromUTC());
1364         } Catch(NullPointerException) {
1365                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1366                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1367         } Catch(WrtDeviceApis::Commons::UnknownException) {
1368                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1369         } Catch (InvalidArgumentException) {
1370                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1371                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
1372         } Catch (PlatformException) {
1373                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1374         }
1375         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1376 }
1377 JSValueRef JSTZDate::isDST(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1378         LoggerD("entered");
1379         Try {
1380                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
1381                 if (!privateObject) {
1382                         LoggerE("Private object is not set.");
1383                         ThrowMsg(NullPointerException, "Private object not initialized");
1384                 }
1385
1386                 TimeUtilConverter converter(context);
1387
1388                 TZDatePtr tzDate(privateObject->getObject());
1389
1390                 return converter.toJSValueRef(tzDate->isDST());
1391         } Catch(NullPointerException) {
1392                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1393                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1394         } Catch(WrtDeviceApis::Commons::UnknownException) {
1395                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1396         } Catch (InvalidArgumentException) {
1397                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1398                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
1399         } Catch (PlatformException) {
1400                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1401         }
1402         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1403 }
1404
1405 JSValueRef JSTZDate::getPreviousDSTTransition(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1406         LoggerD("entered");
1407
1408         Try {
1409                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
1410                 if (!privateObject) {
1411                         LoggerE("Private object is not set.");
1412                         ThrowMsg(NullPointerException, "Private object not initialized");
1413                 }
1414         
1415                 TimeUtilConverter converter(context);
1416
1417                 TZDatePtr tzDate(privateObject->getObject());
1418
1419                 TZDateProperties resultDate =  tzDate->getDSTTransition(TZDate::PREV_TRANSITION);
1420                 if (resultDate.timezone == "")
1421                         return JSValueMakeNull(context);
1422         
1423                 return createJSObject(context, resultDate);
1424         } Catch(NullPointerException) {
1425                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1426                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1427         } Catch(WrtDeviceApis::Commons::UnknownException) {
1428                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1429         } Catch (InvalidArgumentException) {
1430                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1431                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
1432         } Catch (PlatformException) {
1433                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1434         }
1435         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1436 }
1437
1438 JSValueRef JSTZDate::getNextDSTTransition(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1439         LoggerD("entered");
1440
1441         Try {
1442                 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
1443                 if (!privateObject) {
1444                         LoggerE("Private object is not set.");
1445                         ThrowMsg(NullPointerException, "Private object not initialized");
1446                 }
1447         
1448                 TimeUtilConverter converter(context);
1449
1450                 TZDatePtr tzDate(privateObject->getObject());
1451
1452                 TZDateProperties resultDate =  tzDate->getDSTTransition(TZDate::NEXT_TRANSITION);
1453                 if (resultDate.timezone == "")
1454                         return JSValueMakeNull(context);
1455         
1456                 return createJSObject(context, resultDate);
1457         } Catch(NullPointerException) {
1458                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1459                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
1460         } Catch(WrtDeviceApis::Commons::UnknownException) {
1461                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1462         } Catch (InvalidArgumentException) {
1463                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1464                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
1465         } Catch (PlatformException) {
1466                 LoggerE("Exception: " << _rethrown_exception.GetMessage());
1467         }
1468         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
1469 }
1470
1471 }               //DeviceAPI
1472 }               //Time
1473 #undef min