Modify licenses
[scp/ocu/5gnr.git] / Include / vos_time.h
1 /******************************************************************************
2 *
3 *   Copyright (c) 2020 ICT/CAS.
4 *
5 *   Licensed under the O-RAN Software License, Version 1.0 (the "Software 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 *       https://www.o-ran.org/software
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 __VOS_TIME_H__
22 #define __VOS_TIME_H__
23
24 #ifdef  __cplusplus
25 extern "C"{
26 #endif
27
28 #include "vos_types.h"
29
30 #define VOS_TIME_STR_LEN 20
31
32 typedef struct LOCAL_TIME {
33     USHORT usYear;
34     USHORT usMonth;
35     USHORT usDayOfWeek;
36     USHORT usDay;
37     USHORT usHour;
38     USHORT usMinute;
39     USHORT usSecond;
40     USHORT usMilliseconds;
41 }VOS_LOCAL_TIME;
42
43
44
45 /**
46  * 获取当前时间
47  * @param[in]   vos_time     存储时间的指针
48  * @return      成功返回 VOS_OK,失败则返回其他
49  */
50 LONG VOS_local_time( VOS_LOCAL_TIME *vos_time );
51
52
53 /**
54  * 获取当前时间
55  * @param[out]   sys_time     时间
56  * @return      返回值同 sys_time
57  */
58 LONG VOS_time( LONG *sys_time );
59
60 /**
61  * 时间转换,local time 转成秒数
62  * @param[out]   sys_time     时间
63  * @return      返回 sys_time 对应的秒数
64  */
65 LONG VOS_mkTime(const VOS_LOCAL_TIME *sys_time );
66
67
68 /**
69  * 时间转换,秒数 转成local time
70  * @param[out]   sys_time     时间
71  * @param[in ]   time         时间秒数
72  * @return      成功返回 VOS_OK,失败则返回其他
73  */
74 LONG VOS_mkLocalTime( VOS_LOCAL_TIME *sys_time ,LONG time);
75
76
77 /**
78  * 获得时间字符串 YYYY-MM-DD hh:mm:ss
79  *  如果sys_time非空则根据sys_time转换,否则根据time转换,time为0时取当前时间转换,
80  *  转换完成后存入str中
81  * @param[in ]   sys_time     时间
82  * @param[in ]   time         时间秒数
83  * @param[out]   str          时间字符串
84  * @return      指向str的指针
85  */
86 CHAR *VOS_mkLocalTimeStr( VOS_LOCAL_TIME *sys_time ,LONG time,CHAR str[VOS_TIME_STR_LEN]);
87
88
89 /**
90  * 将时间字符串 YYYY-MM-DD hh:mm:ss 转换,为VOS_LOCAL_TIME 和 LONG型
91  *  sys_time和time不为空则填入转换后的值,某一项不需要可以使用NULL
92  * @param[in ]   str          时间字符串
93  * @param[out]   sys_time     时间
94  * @param[out]   time         时间秒数
95  * @return      成功返回 VOS_OK,失败则返回其他
96  */
97 LONG VOS_StrmkLocalTime( CHAR str[VOS_TIME_STR_LEN],VOS_LOCAL_TIME *sys_time ,LONG *time);
98
99
100 /**
101  * 将时间秒数转换成 snmp 时间
102  * @param[in ]   sys_time     时间秒数
103  * @param[out]   snmpTime     时间
104  * @return      成功返回 VOS_OK,失败则返回其他
105  */
106 LONG vos_time2snmp(LONG sys_time,VOS_SNMP_DateAndTime_t *snmpTime);
107
108 #ifdef  __cplusplus
109 }
110 #endif  /* end of __cplusplus */
111
112 #endif  /* end of __VOS_TIME_H__ */