• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 OHOS_GLOBAL_I18N_TIMEZONE_H
16 #define OHOS_GLOBAL_I18N_TIMEZONE_H
17 
18 #include <cstdint>
19 #include <map>
20 #include <png.h>
21 #include <set>
22 #include <string>
23 #include "i18n_types.h"
24 #include "memory"
25 #include "unicode/timezone.h"
26 #include <vector>
27 
28 namespace OHOS {
29 namespace Global {
30 namespace I18n {
31 using GetReplacedTimezoneDisplayName = void (*)(const char*, const char*, char*);
32 
33 class I18nTimeZone {
34 public:
35     I18nTimeZone(std::string &id, bool isZoneID);
36     virtual ~I18nTimeZone();
37     int32_t GetOffset(double date);
38     int32_t GetRawOffset();
39     std::string GetID();
40     std::string GetDisplayName();
41     std::string GetDisplayName(bool isDST);
42     std::string GetDisplayName(std::string localeStr);
43     std::string GetDisplayName(std::string localeStr, bool isDST);
44     virtual std::string GetDisplayNameByTaboo(const std::string& localeStr, std::string result);
45     static std::unique_ptr<I18nTimeZone> CreateInstance(std::string &id, bool isZoneID);
46     static std::set<std::string> GetAvailableIDs(I18nErrorCode &errorCode);
47     static std::set<std::string> GetAvailableZoneCityIDs();
48     static std::string GetCityDisplayName(std::string &cityID, std::string &locale);
49     static std::vector<std::string> GetTimezoneIdByLocation(const double x, const double y);
50     static std::map<std::string, std::string> FindCityDisplayNameMap(std::string &locale);
51     static std::string GetLocaleBaseName(std::string &locale);
52     static std::string GetTimezoneIdByCityId(const std::string &cityId);
53 
54 private:
55     static const char *TIMEZONE_KEY;
56     static const char *DEFAULT_TIMEZONE;
57     static const char *CITY_TIMEZONE_DATA_PATH;
58     static const char *DEVICE_CITY_TIMEZONE_DATA_PATH;
59     static const char *TZ_PIXEL_PATH;
60     static const char *DEFAULT_LOCALE;
61     static const char *CITY_DISPLAYNAME_PATH;
62     static const char *DEVICE_CITY_DISPLAYNAME_PATH;
63     static const char *SUPPORTED_LOCALES_PATH;
64     static const char *TIMEZONE_ROOT_TAG;
65     static const char *TIMEZONE_SECOND_ROOT_TAG;
66     static const char *CITY_DISPLAYNAME_ROOT_TAG;
67     static const char *CITY_DISPLAYNAME_SECOND_ROOT_TAG;
68     static const char *ZONEINFO_PATH;
69     static const uint32_t ELEMENT_NUM = 2;
70     static const uint32_t TZ_X_PLUS = 180;
71     static const uint32_t TZ_HALF_OF_SIZE = 2;
72     static const uint32_t TZ_MAX_PIXEL_VALUE = 255;
73     static constexpr double NUM_PRECISION = 0.1;
74     static std::set<std::string> availableIDs;
75     static std::set<std::string> supportedLocales;
76     static std::set<std::string> availableZoneCityIDs;
77     static std::map<std::string, std::string> city2TimeZoneID;
78     static std::map<int, std::string> categoryNum2TimezoneWN;
79     static std::map<int, std::string> categoryNum2TimezoneEN;
80     static std::map<int, std::string> categoryNum2TimezoneWS;
81     static std::map<int, std::string> categoryNum2TimezoneES;
82     static constexpr int SYS_PARAM_LEN = 128;
83     static bool useDeviceCityDispName;
84     icu::TimeZone *timezone = nullptr;
85 
86     static bool ReadTimeZoneData(const char *xmlPath);
87     static std::string ComputeLocale(std::string &locale);
88     icu::TimeZone* GetTimeZone();
89     static std::string FindCityDisplayNameFromXml(std::string &cityID, std::string &locale);
90     static bool GetSupportedLocales();
91     static std::string GetFallBack(std::string &localeStr);
92     static void GetTimezoneIDFromZoneInfo(std::set<std::string> &availableIDs, std::string &parentPath,
93         std::string &parentName);
94     static std::vector<int> GetColorData(const uint16_t x, const uint16_t y,
95                                          uint16_t actualHeight, std::string preferredPath);
96     static int InitPngptr(png_structp &png_ptr, png_infop &info_ptr, FILE **fp, std::string preferredPath);
97     static std::vector<std::string> FindTzData();
98     static bool ParamExceedScope(const int x, const int y, int fixedX, int fixedY);
99     static std::string GetPreferredPath(const double x, const std::vector<std::string> &filePaths);
100     static void SetVersionPathMap(std::string verison, std::string path,
101             std::map<std::string, std::vector<std::string>> *pathMap);
102     static void GetTzDataWidth(std::vector<std::string> filePaths, uint32_t *width, uint32_t *height);
103     static void CloseFile(FILE *fp);
104     static bool ValidateDataIntegrity(const std::vector<std::string> &pathList);
105     static bool CheckLatitudeAndLongitude(const double x, const double y);
106     static std::map<int, std::string> GetTimeZoneCategoryMap(const double x, const double y);
107 };
108 } // namespace I18n
109 } // namespace Global
110 } // namespace OHOS
111 #endif