• 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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_UTILS_TIME_UTIL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_UTILS_TIME_UTIL_H
18 
19 #include <cstdint>
20 #include <ctime>
21 #include <float.h>
22 
23 #include "base/utils/macros.h"
24 
25 namespace OHOS::Ace {
26 
27 /**
28 * The GetMicroTickCount function get current microseconds since the system was started.
29 */
30 ACE_EXPORT int64_t GetMicroTickCount();
31 
32 int64_t GetSysTimestamp();
33 
34 struct TimeOfNow final {
hoursWest_final35     explicit TimeOfNow(double hoursWest = DBL_MAX) : hoursWest_(hoursWest) {}
36     ~TimeOfNow() = default;
37 
38     // hours west of Greenwich, for e.g., [hoursWest] is [-8] in  UTC+8.
39     // Valid range of [hoursWest] is [-14, 12]. Set default value to DBL_MAX to use current time zone by default.
40     double hoursWest_ = DBL_MAX;
41     int32_t second_ = 0;
42     double minute_ = 0.0;
43     double hour12_ = 0.0; // 12-hour clock
44     double hour24_ = 0.0; // 24-hour clock
45     long timeUsec_ = 0L;   // microsecond. 1 second = 1000 millisecond = 1000000 microsecond
46 };
47 
48 bool IsHoursWestValid(double& hoursWest);
49 
50 TimeOfNow GetTimeOfNow(double hoursWest = DBL_MAX);
51 
52 bool IsDayTime(const TimeOfNow& timeOfNow);
53 
54 } // namespace OHOS::Ace
55 
56 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_UTILS_TIME_UTIL_H
57