2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <CommonsJavaScript/PrivateObject.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <Commons/Exception.h>
24 #include <JSWebAPIErrorFactory.h>
25 #include <ArgumentValidator.h>
27 #include "DurationProperties.h"
29 #include "TimeUtilConverter.h"
32 using namespace DeviceAPI::Common;
33 using namespace WrtDeviceApis::Commons;
34 using namespace WrtDeviceApis::CommonsJavaScript;
36 #define min(a,b) (((a) < (b)) ? (a) : (b))
38 #define TZDATE_ATTRIBUTENAME "TZDate"
43 JSClassDefinition JSTZDate::m_classInfo =
46 kJSClassAttributeNone,
56 NULL, //DeleteProperty,
57 NULL, //GetPropertyNames,
58 NULL, //CallAsFunction,
59 NULL, //CallAsConstructor,
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},
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},
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},
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},
99 {"getTimezone", JSTZDate::getTimezone, kJSPropertyAttributeNone},
100 {"toTimezone", JSTZDate::toTimezone, kJSPropertyAttributeNone},
101 {"toLocalTimezone", JSTZDate::toLocalTimezone, kJSPropertyAttributeNone},
102 {"toUTC", JSTZDate::toUTC, kJSPropertyAttributeNone},
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},
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},
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},
125 JSClassRef JSTZDate::m_jsClassRef = JSClassCreate(JSTZDate::getClassInfo());
127 JSObjectRef JSTZDate::createJSObject(JSContextRef context, TZDatePtr tzDate) {
129 TZDatePrivObject *priv = new TZDatePrivObject(context, tzDate);
131 ThrowMsg(NullPointerException, "Can not new an object");
134 return JSObjectMake(context, getClassRef(), priv);
138 JSObjectRef JSTZDate::createJSObject(JSContextRef context, const bool isNotNull) {
140 TZDatePtr tzDate(new TZDate(isNotNull));
141 return createJSObject(context, tzDate);
144 JSObjectRef JSTZDate::createJSObject(JSContextRef context, const std::string &timezone) {
147 return createJSObject(context);
149 TZDatePtr tzDate(new TZDate(timezone));
150 return createJSObject(context, tzDate);
153 JSObjectRef JSTZDate::createJSObject(JSContextRef context, const double milliseconds, const std::string &timezone) {
157 tzDate = TZDatePtr(new TZDate());
159 tzDate = TZDatePtr(new TZDate(timezone));
161 if (!tzDate->setTime(milliseconds))
162 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Can not set UTC Time");
164 return createJSObject(context, tzDate);
167 JSObjectRef JSTZDate::createJSObject(JSContextRef context, const std::string &dateString, const double milliseconds, const std::string &timezone) {
169 TZDatePtr tzDate = TZDatePtr(new TZDate(dateString, milliseconds, timezone));
171 return createJSObject(context, tzDate);
174 JSObjectRef JSTZDate::createJSObject(JSContextRef context, const TZDateProperties &properties) {
176 TZDatePtr tzDate(new TZDate(properties));
178 return createJSObject(context, tzDate);
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) {
184 TZDateProperties props;
189 props.minutes = minutes;
190 props.seconds = seconds;
191 props.milliseconds = milliseconds;
192 props.timezone = timezone;
194 return createJSObject(context, props);
198 void JSTZDate::initialize(JSContextRef context, JSObjectRef object)
200 LoggerD("entered Nothing to do.");
203 void JSTZDate::finalize(JSObjectRef object)
205 LoggerD( "entered" );
206 TZDatePrivObject *priv =
207 static_cast<TZDatePrivObject*>(JSObjectGetPrivate(object));
212 JSObjectRef JSTZDate::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
215 JSObjectRef tzDate = NULL;
216 ArgumentValidator validator(ctx, argumentCount, arguments);
218 if (argumentCount == 0)
219 tzDate = createJSObject(ctx);
220 else if (argumentCount <= 2) {
221 std::string timezone = "";
223 timezone = validator.toString(1, true);
225 JSObjectRef dateObj = validator.toObject(0, true);
227 JSValueRef dateException = NULL;
229 JSValueRef toStringFuction = JSUtil::getProperty(ctx, dateObj, "toString", NULL);
230 JSObjectRef function = JSUtil::JSValueToObject(ctx, toStringFuction);
232 JSValueRef result = JSObjectCallAsFunction(ctx, function, dateObj, 0, NULL, &dateException);
234 ThrowMsg(ConversionException, "Couldn't get date string");
236 std::string stringDate = JSUtil::JSValueToString(ctx, result);
238 stringDate.erase(stringDate.find(" GMT"));
240 JSValueRef getMiliSecFuction = JSUtil::getProperty(ctx, dateObj, "getMilliseconds", NULL);
241 function = JSUtil::JSValueToObject(ctx, getMiliSecFuction);
243 result = JSObjectCallAsFunction(ctx, function, dateObj, 0, NULL, &dateException);
245 ThrowMsg(ConversionException, "Couldn't get milliseconds");
247 long millisec = JSUtil::JSValueToLong(ctx, result);
248 LoggerD("getMilliseconds = " << millisec);
249 tzDate = createJSObject(ctx, stringDate, millisec, timezone);
251 } catch (const BasePlatformException& err) {
252 LoggerE(err.getName() << ":"<<err.getMessage());
254 TZDatePrivObject *priv = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(tzDate));
259 } catch (const WrtDeviceApis::Commons::Exception& err) {
260 LoggerE(err.GetClassName() << ":"<<err.GetMessage());
262 TZDatePrivObject *priv = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(tzDate));
269 tzDate = createJSObject(ctx, timezone);
271 TZDateProperties prop;
272 prop.year = validator.toLong(0);
273 if ((prop.year >= 0) && (prop.year <= 99))
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);
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());
295 tzDate = createJSObject(ctx, false);
297 JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
298 JSObjectSetProperty(ctx, tzDate, ctorName, constructor,
299 kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
300 JSStringRelease(ctorName);
303 const JSClassRef JSTZDate::getClassRef()
306 m_jsClassRef = JSClassCreate(&m_classInfo);
311 const JSClassDefinition* JSTZDate::getClassInfo()
316 JSValueRef JSTZDate::getTimezone(JSContextRef context, JSObjectRef function,
317 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
319 TimeUtilConverter converter(context);
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");
328 TZDatePtr tzDate(privateObject->getObject());
329 std::string timezone = tzDate->getTimezone();
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());
341 return converter.toJSValueRef("Invalid Date");
344 JSValueRef JSTZDate::toTimezone(JSContextRef context, JSObjectRef function,
345 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
349 ArgumentValidator validator(context, argumentCount, arguments);
350 std::string timezone = validator.toString(0);
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");
358 TZDatePtr tzDate(privateObject->getObject());
359 if ((timezone == "") || (!tzDate->isAvailableTimezone(timezone)))
360 ThrowMsg(InvalidArgumentException, "Unsupported Timezone.");
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());
381 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
384 JSValueRef JSTZDate::diffTZDate(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception, CompareType type) {
387 ArgumentValidator validator(context, argumentCount, arguments);
388 if (!validator.toObject(0, JSTZDate::getClassRef(), false))
389 ThrowMsg(ConversionException, "Parameter is not TZDate");
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");
396 TimeUtilConverter converter(context);
397 TZDatePtr tzDate(privateObject->getObject());
398 long long cmpResult = tzDate->difference(converter.getPropertiesInTZDate(arguments[0]));
404 return converter.toJSValueRef(true);
406 return converter.toJSValueRef(false);
411 return converter.toJSValueRef(true);
413 return converter.toJSValueRef(false);
418 return converter.toJSValueRef(true);
420 return converter.toJSValueRef(false);
424 return converter.makeMillisecondDurationObject(cmpResult);
428 JSValueRef JSTZDate::difference(JSContextRef context, JSObjectRef function,
429 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
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());
449 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
452 JSValueRef JSTZDate::equalsTo(JSContextRef context, JSObjectRef function,
453 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
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());
472 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
475 JSValueRef JSTZDate::earlierThan(JSContextRef context, JSObjectRef function,
476 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
477 LoggerD("earlierThan entered");
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());
495 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
499 JSValueRef JSTZDate::laterThan(JSContextRef context, JSObjectRef function,
500 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
502 LoggerD("laterThan entered");
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());
520 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
524 JSValueRef JSTZDate::addDuration(JSContextRef context, JSObjectRef function,
525 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
527 LoggerD("addDuration entered");
529 TimeUtilConverter converter(context);
531 DurationProperties duration;
532 if (argumentCount == 0)
533 duration= converter.getDurationProperties(JSValueMakeUndefined(context));
535 duration= converter.getDurationProperties(arguments[0]);
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");
544 TZDatePtr tzDate(privateObject->getObject());
545 TZDateProperties result = tzDate->addDuration(duration);
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.");
564 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
567 JSValueRef JSTZDate::toUTC(JSContextRef context, JSObjectRef function,
568 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
570 LoggerD("toUTC entered");
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");
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());
592 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
596 JSValueRef JSTZDate::toLocalTimezone(JSContextRef context, JSObjectRef function,
597 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
599 LoggerD("toLocalTimezone entered");
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");
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());
618 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
621 JSValueRef JSTZDate::toLocaleDateString(JSContextRef context, JSObjectRef function,
622 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
624 TimeUtilConverter converter(context);
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");
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());
644 return converter.toJSValueRef("Invalid Date");
647 JSValueRef JSTZDate::toLocaleTimeString(JSContextRef context, JSObjectRef function,
648 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
650 TimeUtilConverter converter(context);
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");
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());
670 return converter.toJSValueRef("Invalid Date");
673 JSValueRef JSTZDate::toLocaleString(JSContextRef context, JSObjectRef function,
674 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
676 TimeUtilConverter converter(context);
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");
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());
696 return converter.toJSValueRef("Invalid Date");
699 JSValueRef JSTZDate::toDateString(JSContextRef context, JSObjectRef function,
700 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
702 TimeUtilConverter converter(context);
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");
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());
722 return converter.toJSValueRef("Invalid Date");
725 JSValueRef JSTZDate::toTimeString(JSContextRef context, JSObjectRef function,
726 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
728 TimeUtilConverter converter(context);
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");
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());
748 return converter.toJSValueRef("Invalid Date");
752 JSValueRef JSTZDate::toString(JSContextRef context, JSObjectRef function,
753 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
755 TimeUtilConverter converter(context);
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");
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());
775 return converter.toJSValueRef("Invalid Date");
778 JSValueRef JSTZDate::getDate(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
779 JSValueRef * exception) {
782 TZDate::TZDateFields dateFields = TZDate::TZDATE_DATE;
783 return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
786 JSValueRef JSTZDate::getDay(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
787 JSValueRef * exception) {
790 TZDate::TZDateFields dateFields = TZDate::TZDATE_DAY_OF_WEEK;
791 return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
794 JSValueRef JSTZDate::getFullYear(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
795 JSValueRef * exception) {
798 TZDate::TZDateFields dateFields = TZDate::TZDATE_YEAR;
799 return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
802 JSValueRef JSTZDate::getHours(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
803 JSValueRef * exception) {
806 TZDate::TZDateFields dateFields = TZDate::TZDATE_HOUR_OF_DAY;
807 return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
810 JSValueRef JSTZDate::getMilliseconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
811 JSValueRef * exception) {
814 TZDate::TZDateFields dateFields = TZDate::TZDATE_MILLISECOND;
815 return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
816 } //getMilliseconds()
818 JSValueRef JSTZDate::getMinutes(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
819 JSValueRef * exception) {
822 TZDate::TZDateFields dateFields = TZDate::TZDATE_MINUTE;
823 return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
826 JSValueRef JSTZDate::getMonth(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
827 JSValueRef * exception) {
829 TZDate::TZDateFields dateFields = TZDate::TZDATE_MONTH;
830 return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
833 JSValueRef JSTZDate::getSeconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
834 JSValueRef * exception) {
837 TZDate::TZDateFields dateFields = TZDate::TZDATE_SECOND;
838 return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
841 JSValueRef JSTZDate::getTZDateValue(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception,
842 TZDate::TZDateFields dateFields) {
843 TimeUtilConverter converter(context);
845 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*> (JSObjectGetPrivate(thisObject));
847 if (privateObject == NULL) {
848 LoggerE(">>> NULL Exception");
849 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type Mismatch");
852 TZDatePtr tzDate(privateObject->getObject());
853 long retVal = tzDate->get(dateFields);
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());
866 return converter.toJSValueRef(0);
869 JSValueRef JSTZDate::setDate(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
870 JSValueRef * exception) {
873 TZDate::TZDateFields dateFields = TZDate::TZDATE_DATE;
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());
892 return JSValueMakeUndefined(context);
895 JSValueRef JSTZDate::setFullYear(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
896 JSValueRef * exception) {
899 TZDate::TZDateFields dateFields = TZDate::TZDATE_YEAR;
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());
916 return JSValueMakeUndefined(context);
919 JSValueRef JSTZDate::setHours(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
920 JSValueRef * exception) {
923 TZDate::TZDateFields dateFields = TZDate::TZDATE_HOUR_OF_DAY;
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());
940 return JSValueMakeUndefined(context);
943 JSValueRef JSTZDate::setMilliseconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
944 JSValueRef * exception) {
947 TZDate::TZDateFields dateFields = TZDate::TZDATE_MILLISECOND;
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());
964 return JSValueMakeUndefined(context);
965 } //setMilliseconds()
967 JSValueRef JSTZDate::setMinutes(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
968 JSValueRef * exception) {
971 TZDate::TZDateFields dateFields = TZDate::TZDATE_MINUTE;
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());
988 return JSValueMakeUndefined(context);
991 JSValueRef JSTZDate::setMonth(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
992 JSValueRef * exception) {
995 TZDate::TZDateFields dateFields = TZDate::TZDATE_MONTH;
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());
1012 return JSValueMakeUndefined(context);
1015 JSValueRef JSTZDate::setSeconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
1016 JSValueRef * exception) {
1019 TZDate::TZDateFields dateFields = TZDate::TZDATE_SECOND;
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());
1036 return JSValueMakeUndefined(context);
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);
1046 TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*> (JSObjectGetPrivate(thisObject));
1048 if (privateObject == NULL) {
1049 LoggerE(">>> NULL Exception");
1050 ThrowMsg(NullPointerException, "privateObject is NULL");
1053 TZDatePtr tzDate(privateObject->getObject());
1054 tzDate->set(dateFields,data);
1056 return JSValueMakeUndefined(context);
1059 JSValueRef JSTZDate::getUTCDate(JSContextRef context, JSObjectRef function,
1060 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1062 return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_DATE, exception);
1065 JSValueRef JSTZDate::getUTCDay(JSContextRef context, JSObjectRef function,
1066 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1068 return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_DAY_OF_WEEK, exception);
1071 JSValueRef JSTZDate::getUTCFullYear(JSContextRef context, JSObjectRef function,
1072 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1074 return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_YEAR, exception);
1077 JSValueRef JSTZDate::getUTCHours(JSContextRef context, JSObjectRef function,
1078 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1080 return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_HOUR_OF_DAY, exception);
1083 JSValueRef JSTZDate::getUTCMilliseconds(JSContextRef context, JSObjectRef function,
1084 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1086 return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_MILLISECOND, exception);
1089 JSValueRef JSTZDate::getUTCMinutes(JSContextRef context, JSObjectRef function,
1090 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1092 return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_MINUTE, exception);
1095 JSValueRef JSTZDate::getUTCMonth(JSContextRef context, JSObjectRef function,
1096 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1098 return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_MONTH, exception);
1101 JSValueRef JSTZDate::getUTCSeconds(JSContextRef context, JSObjectRef function,
1102 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1104 return getUTCTZDateValue(context, thisObject, argumentCount, TZDate::TZDATE_SECOND, exception);
1107 JSValueRef JSTZDate::getUTCTZDateValue(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, TZDate::TZDateFields DateFields, JSValueRef * exception) {
1109 TimeUtilConverter converter(context);
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");
1117 TZDatePtr tzDate(privateObject->getObject());
1118 long result = tzDate->getUTC(DateFields);
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());
1132 return converter.toJSValueRef(0);
1135 JSValueRef JSTZDate::setUTCDate(JSContextRef context, JSObjectRef function,
1136 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1139 return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_DATE, exception);
1142 JSValueRef JSTZDate::setUTCFullYear(JSContextRef context, JSObjectRef function,
1143 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1146 return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_YEAR, exception);
1149 JSValueRef JSTZDate::setUTCHours(JSContextRef context, JSObjectRef function,
1150 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1153 return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_HOUR_OF_DAY, exception);
1156 JSValueRef JSTZDate::setUTCMilliseconds(JSContextRef context, JSObjectRef function,
1157 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1160 return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_MILLISECOND, exception);
1163 JSValueRef JSTZDate::setUTCMinutes(JSContextRef context, JSObjectRef function,
1164 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1167 return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_MINUTE, exception);
1170 JSValueRef JSTZDate::setUTCMonth(JSContextRef context, JSObjectRef function,
1171 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1174 return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_MONTH, exception);
1177 JSValueRef JSTZDate::setUTCSeconds(JSContextRef context, JSObjectRef function,
1178 JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1181 return setUTCTZDateValue(context, thisObject, argumentCount, arguments, TZDate::TZDATE_SECOND, exception);
1184 JSValueRef JSTZDate::setUTCTZDateValue(JSContextRef context, JSObjectRef thisObject,
1185 size_t argumentCount, const JSValueRef arguments[], TZDate::TZDateFields dateFields, JSValueRef * exception) {
1188 TimeUtilConverter converter(context);
1191 if (argumentCount == 0)
1192 data = converter.toLong(JSValueMakeUndefined(context));
1194 data = converter.toLong(arguments[0]);
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");
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());
1216 return JSValueMakeUndefined(context);
1219 JSValueRef JSTZDate::getTimezoneAbbreviation(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
1221 TimeUtilConverter converter(context);
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");
1229 TZDatePtr tzDate(privateObject->getObject());
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());
1242 return converter.toJSValueRef("Invalid Date");
1245 JSValueRef JSTZDate::secondsFromUTC(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
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");
1255 TimeUtilConverter converter(context);
1257 TZDatePtr tzDate(privateObject->getObject());
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());
1269 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
1271 JSValueRef JSTZDate::isDST(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
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");
1280 TimeUtilConverter converter(context);
1282 TZDatePtr tzDate(privateObject->getObject());
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());
1294 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
1297 JSValueRef JSTZDate::getPreviousDSTTransition(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
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");
1307 TimeUtilConverter converter(context);
1309 TZDatePtr tzDate(privateObject->getObject());
1311 TZDateProperties resultDate = tzDate->getDSTTransition(TZDate::PREV_TRANSITION);
1312 if (resultDate.timezone == "")
1313 return JSValueMakeNull(context);
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());
1325 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");
1328 JSValueRef JSTZDate::getNextDSTTransition(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
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");
1338 TimeUtilConverter converter(context);
1340 TZDatePtr tzDate(privateObject->getObject());
1342 TZDateProperties resultDate = tzDate->getDSTTransition(TZDate::NEXT_TRANSITION);
1343 if (resultDate.timezone == "")
1344 return JSValueMakeNull(context);
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());
1356 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, "Unknown Error");