1 /*
2  * Copyright (c) 2023 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 
16 #ifndef FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_INCLUDE_TIME_PROVIDER_H
17 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_INCLUDE_TIME_PROVIDER_H
18 
19 #include <ctime>
20 #include <cstdint>
21 
22 namespace OHOS {
23 namespace DevStandbyMgr {
24 enum ClockType {
25     CLOCK_TYPE_REALTIME = CLOCK_REALTIME,
26     CLOCK_TYPE_MONOTONIC = CLOCK_MONOTONIC,
27 };
28 
29 enum TimeConstant : int64_t {
30     NSEC_PER_MIN = 60000000000LL,
31     NSEC_PER_SEC = 1000000000LL,
32     NSEC_PER_MSEC = 1000000LL,
33     NSEC_PER_USEC = 1000LL,
34     USEC_PER_SEC = 1000000LL,
35     USEC_PER_MSEC = 1000LL,
36     MSEC_PER_DAY = 86400000LL,
37     MSEC_PER_DAWN = 21600000LL,
38     MSEC_PER_HOUR = 3600000LL,
39     MSEC_PER_MIN = 60000LL,
40     MSEC_PER_SEC = 1000LL,
41     SEC_PER_MIN = 60LL,
42     SEC_PER_HOUR = 3600LL,
43     SEC_PER_DAY = 86400LL,
44     MIN_PER_HOUR = 60LL,
45     HOUR_PER_DAY = 24LL,
46 };
47 
48 class TimeProvider {
49 public:
50     static bool ConvertTimeStampToLocalTime(int64_t curTimeStamp, struct tm& curLocalTime);
51     static uint32_t GetCondition(int64_t afterNextSeconds = 0);
52     static int64_t GetNapTimeOut();
53     static bool TimeDiffToDayNightSwitch(int64_t& timeDiff);
54     static int32_t GetRandomDelay(int32_t low, int32_t high);
55     static bool DiffToFixedClock(int64_t curTimeStamp, int32_t tmHour, int32_t tmMin, int64_t& timeDiff);
56     static int32_t GetCurrentDate();
57 
58 #ifdef STANDBY_POWER_MANAGER_ENABLE
59 private:
60     static bool IsPowerSaveMode();
61 #endif
62 };
63 }  // namespace DevStandbyMgr
64 }  // namespace OHOS
65 #endif  // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_SERVICES_INCLUDE_TIME_PROVIDER_H