• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef POWERMGR_POWER_MGR_TIME_UTIL_H
16 #define POWERMGR_POWER_MGR_TIME_UTIL_H
17 
18 #include <stdint.h>
19 
20 #include <time.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif // __cplusplus
25 
26 enum {
27     NSEC_PER_MIN = 60000000000LL,
28     NSEC_PER_SEC = 1000000000LL,
29     NSEC_PER_MSEC = 1000000LL,
30     NSEC_PER_USEC = 1000LL,
31     USEC_PER_SEC = 1000000LL,
32     USEC_PER_MSEC = 1000LL,
33     MSEC_PER_DAY = 86400000LL,
34     MSEC_PER_HOUR = 3600000LL,
35     MSEC_PER_MIN = 60000LL,
36     MSEC_PER_SEC = 1000LL,
37     SEC_PER_MIN = 60LL,
38     SEC_PER_HOUR = 3600LL,
39     SEC_PER_DAY = 86400LL,
40     MIN_PER_HOUR = 60LL,
41     HOUR_PER_DAY = 24LL,
42 };
43 
NsecToUsec(int64_t nsec)44 static inline int64_t NsecToUsec(int64_t nsec)
45 {
46     return nsec / NSEC_PER_USEC;
47 }
48 
NsecToMsec(int64_t nsec)49 static inline int64_t NsecToMsec(int64_t nsec)
50 {
51     return nsec / NSEC_PER_MSEC;
52 }
53 
UsecToMsec(int64_t usec)54 static inline int64_t UsecToMsec(int64_t usec)
55 {
56     return usec / USEC_PER_MSEC;
57 }
58 
MsecToNsec(int64_t msec)59 static inline int64_t MsecToNsec(int64_t msec)
60 {
61     return msec * NSEC_PER_MSEC;
62 }
63 
MsecToUsec(int64_t msec)64 static inline int64_t MsecToUsec(int64_t msec)
65 {
66     return msec * USEC_PER_MSEC;
67 }
68 
MsecToSec(int64_t msec)69 static inline int64_t MsecToSec(int64_t msec)
70 {
71     return msec / MSEC_PER_SEC;
72 }
73 
MsecToMin(int64_t msec)74 static inline int64_t MsecToMin(int64_t msec)
75 {
76     return msec / MSEC_PER_MIN;
77 }
78 
MsecToHour(int64_t msec)79 static inline int64_t MsecToHour(int64_t msec)
80 {
81     return msec / MSEC_PER_HOUR;
82 }
83 
SecToNsec(int64_t sec)84 static inline int64_t SecToNsec(int64_t sec)
85 {
86     return sec * NSEC_PER_SEC;
87 }
88 
SecToMsec(int64_t sec)89 static inline int64_t SecToMsec(int64_t sec)
90 {
91     return sec * MSEC_PER_SEC;
92 }
93 
MinToNsec(int64_t mins)94 static inline int64_t MinToNsec(int64_t mins)
95 {
96     return mins * NSEC_PER_MIN;
97 }
98 
MinToMsec(int64_t mins)99 static inline int64_t MinToMsec(int64_t mins)
100 {
101     return mins * MSEC_PER_MIN;
102 }
103 
HourToMsec(int64_t hour)104 static inline int64_t HourToMsec(int64_t hour)
105 {
106     return hour * MSEC_PER_HOUR;
107 }
108 
DayToMsec(int64_t day)109 static inline int64_t DayToMsec(int64_t day)
110 {
111     return day * MSEC_PER_DAY;
112 }
113 
114 int64_t GetCurrentTimeMsec(clockid_t clkId);
115 
116 #ifdef __cplusplus
117 }
118 #endif // __cplusplus
119 #endif // POWERMGR_POWER_MGR_TIME_UTIL_H
120