Update wrt-plugins-common_0.3.53
[framework/web/wrt-plugins-common.git] / src / 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
28 struct tm* localtime_r(long long int* timep, struct tm* result)
29 {
30     UErrorCode status = U_ZERO_ERROR;
31     UCalendar *cal;
32
33     if( !result || !timep )
34     {
35         return NULL;
36     }
37
38     cal = ucal_open(NULL, 0, NULL, UCAL_DEFAULT, &status);
39
40     if(U_FAILURE(status))
41     {
42         return NULL;
43     }
44
45     ucal_setMillis(cal, (*timep * (double)1000.0), &status);
46
47     result->tm_sec  = ucal_get(cal, UCAL_SECOND,       &status);
48     result->tm_min  = ucal_get(cal, UCAL_MINUTE,       &status);
49     result->tm_hour = ucal_get(cal, UCAL_HOUR,         &status);
50     result->tm_mday = ucal_get(cal, UCAL_DAY_OF_MONTH, &status);
51     result->tm_mon  = ucal_get(cal, UCAL_MONTH,        &status);
52     result->tm_year = ucal_get(cal, UCAL_YEAR,         &status);
53     result->tm_wday = ucal_get(cal, UCAL_DAY_OF_WEEK,  &status);
54     result->tm_yday = ucal_get(cal, UCAL_DAY_OF_YEAR,  &status);
55     result->tm_isdst= ucal_get(cal, UCAL_DST_OFFSET,   &status);
56
57     ucal_close(cal);
58
59     if(U_FAILURE(status))
60     {
61         return NULL;
62     }
63     else
64     {
65         return result;
66     }
67 }
68
69 }
70 }
71 }