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 #include "base/raw_data_base_def.h"
17 
18 #include <vector>
19 
20 namespace OHOS {
21 namespace HiviewDFX {
22 namespace EventRaw {
23 namespace {
24 constexpr unsigned int DEFAULT_TZ_POS = 14; // default "+0000"
25 
26 static std::vector<std::string> ALL_TIME_ZONES {
27     "-0100", "-0200", "-0300", "-0330", "-0400", "-0500", "-0600",
28     "-0700", "-0800", "-0900", "-0930", "-1000", "-1100", "-1200",
29     "+0000", "+0100", "+0200", "+0300", "+0330", "+0400", "+0430",
30     "+0500", "+0530", "+0545", "+0600", "+0630", "+0700", "+0800",
31     "+0845", "+0900", "+0930", "+1000", "+1030", "+1100", "+1200",
32     "+1245", "+1300", "+1400"
33 };
34 }
ParseTimeZone(const std::string & tzStr)35 int ParseTimeZone(const std::string& tzStr)
36 {
37     int ret = DEFAULT_TZ_POS;
38     for (auto iter = ALL_TIME_ZONES.begin(); iter < ALL_TIME_ZONES.end(); ++iter) {
39         if (*iter == tzStr) {
40             ret = (iter - ALL_TIME_ZONES.begin());
41             break;
42         }
43     }
44     return ret;
45 }
46 
ParseTimeZone(const uint8_t tzVal)47 std::string ParseTimeZone(const uint8_t tzVal)
48 {
49     if (tzVal >= ALL_TIME_ZONES.size()) {
50         return ALL_TIME_ZONES.at(DEFAULT_TZ_POS);
51     }
52     return ALL_TIME_ZONES.at(tzVal);
53 }
54 
GetValidDataMinimumByteCount()55 size_t GetValidDataMinimumByteCount()
56 {
57     return sizeof(int32_t) + sizeof(struct EventRaw::HiSysEventHeader);
58 }
59 } // namespace EventRaw
60 } // namespace HiviewDFX
61 } // namespace OHOS