tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / TimeUtil / TimeUtilConverter.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18
19
20
21 #ifndef _JS_TIZEN_TIMEUTIL_CONVERTER_H_
22 #define _JS_TIZEN_TIMEUTIL_CONVERTER_H_
23
24 #include <vector>
25 #include <string>
26
27 #include <CommonsJavaScript/Converter.h>
28 #include <CommonsJavaScript/ScopedJSStringRef.h>
29
30 #include "TZDate.h"
31 #include "DurationProperties.h"
32
33 #ifdef IMPL_BACKWARD_COMPATIBLE
34 #include "TZDateProperties.h"
35 #endif // IMPL_BACKWARD_COMPATIBLE
36
37 using namespace WrtDeviceApis::CommonsJavaScript;
38
39 namespace DeviceAPI {
40 namespace Time {
41
42
43 class TimeUtilConverter : public Converter {
44 public:
45     using Converter::toJSValueRef;
46
47 public:
48     explicit TimeUtilConverter(JSContextRef context);
49     virtual  ~TimeUtilConverter();
50     short toShort(const JSValueRef& arg);
51
52     TZDateProperties getPropertiesInTZDate(JSValueRef arg);
53     TZDateProperties getPropertiesInTZDate(JSObjectRef arg);
54     JSObjectRef makeDurationObject(const DurationProperties &duration);
55     JSObjectRef makeMillisecondDurationObject(const long long length);
56     DurationPropertiesPtr getDuration(JSValueRef value);
57     DurationProperties getDurationProperties(JSValueRef value);
58     long long getDurationLength(JSValueRef value);
59     long long getDurationLength(JSObjectRef object);
60     short getDurationUnit(JSValueRef value);
61     short getDurationUnit(JSObjectRef object);
62     short toDurationUnit(std::string strUnit);
63     std::string toDurationUnitString(short unit);
64     long long convertDurationLength(DurationProperties duration, short unit);
65     double getTimeInMilliseconds(JSValueRef arg);
66     double getTimeInMilliseconds(JSObjectRef arg);
67     tm toTZDateTime(JSValueRef arg);
68     tm toTZDateTime(JSObjectRef arg);
69     JSObjectRef toJSValueRefTZDate(const double milliseconds, const std::string &timezone);
70     DurationProperties optimizedTimeDuration(DurationProperties origin);
71 };
72
73 } // Time
74 } // DeviceAPI
75
76 #endif /* _JS_TIZEN_TIMEUTIL_CONVERTER_H_ */