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