2 * Copyright (c) 2000-2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (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
8 * http://floralicense.org/license/
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.
18 * @file DTapps2Time.cpp
19 * @brief This file includes functions relating to TIME APIs.
22 #include "DTapps2Time.h"
24 BOOL DTappsDtTmStr2Sec(unsigned char *time_str,time_t *TotalSec)
27 char short_str[5] = {0};
30 memset(&time_fmt, 0x00, sizeof(time_fmt));
32 TAPPS_GSTRLCPY(str, (const char*)time_str, sizeof(str));
34 DRM_TAPPS_LOG("str = %s",str);
36 if(str[4] != '-' || str[7] != '-' || str[10] != 'T' || str[13] != ':' || str[16] != ':')
38 DRM_TAPPS_EXCEPTION("Format is incorrect:str=%s", str);
43 DTAPPS_MEMCPY(short_str, str, 4);
44 time_fmt.tm_year = DTAPPS_ATOI(short_str) - 1900;
45 DRM_TAPPS_FRQ_LOG("tm_year = %d", time_fmt.tm_year);
47 DTAPPS_MEMSET(short_str, 0x0,5);
48 DTAPPS_MEMCPY(short_str, str + 5, 2);
49 time_fmt.tm_mon = DTAPPS_ATOI(short_str) - 1;
50 DRM_TAPPS_FRQ_LOG("tm_mon = %d", time_fmt.tm_mon);
52 DTAPPS_MEMCPY(short_str, str + 8, 2);
53 time_fmt.tm_mday = DTAPPS_ATOI(short_str);
54 DRM_TAPPS_FRQ_LOG("tm_mday = %d", time_fmt.tm_mday);
55 DTAPPS_MEMCPY(short_str, str + 11, 2);
56 time_fmt.tm_hour = DTAPPS_ATOI(short_str);
57 DRM_TAPPS_FRQ_LOG("tm_hour = %d", time_fmt.tm_hour);
59 DTAPPS_MEMCPY(short_str, str + 14, 2);
60 time_fmt.tm_min = DTAPPS_ATOI(short_str);
61 DRM_TAPPS_FRQ_LOG("tm_min = %d", time_fmt.tm_min);
63 DTAPPS_MEMCPY(short_str, str + 17, 2);
64 time_fmt.tm_sec = DTAPPS_ATOI(short_str);
65 DRM_TAPPS_FRQ_LOG("tm_sec = %d", time_fmt.tm_sec);
67 /* Convert into Seconds */
68 *TotalSec = DTAPPS_MKTIME(&time_fmt);
69 DRM_TAPPS_LOG("TotalSec = %lu", *TotalSec);
74 BOOL DTappsDtTmStr2StrucTm(unsigned char *time_str,struct tm *time_fmt)
77 char short_str[5] = {0};
79 TAPPS_GSTRLCPY(str, (const char*)time_str, sizeof(str));
81 DRM_TAPPS_LOG("str = %s", str);
83 if(str[4]!='-' || str[7]!='-' || str[10]!='T' || str[13]!=':' || str[16]!=':')
85 DRM_TAPPS_EXCEPTION("Format is incorrect:str=%s", str);
90 DTAPPS_MEMCPY(short_str, str, 4);
91 time_fmt->tm_year = DTAPPS_ATOI(short_str) - 1900;
92 DRM_TAPPS_FRQ_LOG("tm_year = %d", time_fmt->tm_year);
94 DTAPPS_MEMSET(short_str, 0x0, 5);
95 DTAPPS_MEMCPY(short_str, str + 5, 2);
96 time_fmt->tm_mon = DTAPPS_ATOI(short_str) - 1;
97 DRM_TAPPS_FRQ_LOG("tm_mon = %d", time_fmt->tm_mon);
99 DTAPPS_MEMCPY(short_str, str + 8, 2);
100 time_fmt->tm_mday = DTAPPS_ATOI(short_str);
101 DRM_TAPPS_FRQ_LOG("tm_mday = %d", time_fmt->tm_mday);
103 DTAPPS_MEMCPY(short_str, str + 11, 2);
104 time_fmt->tm_hour = DTAPPS_ATOI(short_str);
105 DRM_TAPPS_FRQ_LOG("tm_hour = %d", time_fmt->tm_hour);
107 DTAPPS_MEMCPY(short_str, str + 14, 2);
108 time_fmt->tm_min = DTAPPS_ATOI(short_str);
109 DRM_TAPPS_FRQ_LOG("tm_min = %d", time_fmt->tm_min);
111 DTAPPS_MEMCPY(short_str, str + 17, 2);
112 time_fmt->tm_sec = DTAPPS_ATOI(short_str);
113 DRM_TAPPS_FRQ_LOG("tm_sec = %d", time_fmt->tm_sec);
118 BOOL DTappsGetSecureTime(time_t* seconds)
120 time_t now = 0, secure_sec = 0;
124 memset(&gm_fmt, 0x00, sizeof(gm_fmt));
126 now = DTAPPS_TIME(NULL);
128 /* TODO: Read the Delta from VCONF */
130 secure_sec = now + Delta;
132 /* Operations to be done in GMT - Convert this to GM Time */
133 DTAPPS_GMTIME_THREAD_SAFE(&secure_sec, &gm_fmt);
134 *seconds = DTAPPS_MKTIME(&gm_fmt);
136 DRM_TAPPS_LOG("now = %d, secure_sec = %d, seconds(SecureTime in GMT) = %d", now, secure_sec, *seconds);