Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_wearable / Commons / TimeUtils.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file   TimeUtils.h
18  * @author Tae-Jeong Lee (taejeong.lee@samsung.com)
19  */
20
21 #include "TimeUtils.h"
22 #include <unicode/ucal.h>
23
24 namespace WrtDeviceApis {
25 namespace Commons {
26 namespace Time {
27 struct tm* localtime_r(long long int* timep, struct tm* result)
28 {
29     UErrorCode status = U_ZERO_ERROR;
30     UCalendar *cal;
31
32     if (!result || !timep) {
33         return NULL;
34     }
35
36     cal = ucal_open(NULL, 0, NULL, UCAL_DEFAULT, &status);
37
38     if (U_FAILURE(status)) {
39         return NULL;
40     }
41
42     ucal_setMillis(cal, (*timep * (double)1000.0), &status);
43
44     result->tm_sec = ucal_get(cal, UCAL_SECOND, &status);
45     result->tm_min = ucal_get(cal, UCAL_MINUTE, &status);
46     result->tm_hour = ucal_get(cal, UCAL_HOUR, &status);
47     result->tm_mday = ucal_get(cal, UCAL_DAY_OF_MONTH, &status);
48     result->tm_mon = ucal_get(cal, UCAL_MONTH, &status);
49     result->tm_year = ucal_get(cal, UCAL_YEAR, &status);
50     result->tm_wday = ucal_get(cal, UCAL_DAY_OF_WEEK, &status);
51     result->tm_yday = ucal_get(cal, UCAL_DAY_OF_YEAR, &status);
52     result->tm_isdst = ucal_get(cal, UCAL_DST_OFFSET, &status);
53
54     ucal_close(cal);
55
56     if (U_FAILURE(status)) {
57         return NULL;
58     } else {
59         return result;
60     }
61 }
62 }
63 }
64 }