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 class I18nTimeZone { 32 public: 33 I18nTimeZone(std::string &id, bool isZoneID); 34 ~I18nTimeZone(); 35 int32_t GetOffset(double date); 36 int32_t GetRawOffset(); 37 std::string GetID(); 38 std::string GetDisplayName(); 39 std::string GetDisplayName(bool isDST); 40 std::string GetDisplayName(std::string localeStr); 41 std::string GetDisplayName(std::string localeStr, bool isDST); 42 static std::unique_ptr<I18nTimeZone> CreateInstance(std::string &id, bool isZoneID); 43 static std::set<std::string> GetAvailableIDs(I18nErrorCode &errorCode); 44 static std::set<std::string> GetAvailableZoneCityIDs(); 45 static std::string GetCityDisplayName(std::string &cityID, std::string &locale); 46 static std::vector<std::string> GetTimezoneIdByLocation(const double x, const double y); 47 static std::map<std::string, std::string> FindCityDisplayNameMap(std::string &locale); 48 static std::string GetLocaleBaseName(std::string &locale); 49 static std::string GetTimezoneIdByCityId(const std::string &cityId); 50 51 private: 52 static const char *TIMEZONE_KEY; 53 static const char *DEFAULT_TIMEZONE; 54 static const char *CITY_TIMEZONE_DATA_PATH; 55 static const char *DEVICE_CITY_TIMEZONE_DATA_PATH; 56 static const char *TZ_PIXEL_PATH; 57 static const char *DEFAULT_LOCALE; 58 static const char *CITY_DISPLAYNAME_PATH; 59 static const char *DEVICE_CITY_DISPLAYNAME_PATH; 60 static const char *SUPPORTED_LOCALES_PATH; 61 static const char *TIMEZONE_ROOT_TAG; 62 static const char *TIMEZONE_SECOND_ROOT_TAG; 63 static const char *CITY_DISPLAYNAME_ROOT_TAG; 64 static const char *CITY_DISPLAYNAME_SECOND_ROOT_TAG; 65 static const char *ZONEINFO_PATH; 66 static const uint32_t ELEMENT_NUM = 2; 67 static const uint32_t TZ_X_PLUS = 180; 68 static const uint32_t TZ_HALF_OF_SIZE = 2; 69 static const uint32_t TZ_MAX_PIXEL_VALUE = 255; 70 static std::set<std::string> availableIDs; 71 static std::set<std::string> supportedLocales; 72 static std::set<std::string> availableZoneCityIDs; 73 static std::map<std::string, std::string> city2TimeZoneID; 74 static std::map<int, std::string> categoryNum2TimezoneWN; 75 static std::map<int, std::string> categoryNum2TimezoneEN; 76 static std::map<int, std::string> categoryNum2TimezoneWS; 77 static std::map<int, std::string> categoryNum2TimezoneES; 78 static constexpr int SYS_PARAM_LEN = 128; 79 static bool useDeviceCityDispName; 80 icu::TimeZone *timezone = nullptr; 81 82 static bool ReadTimeZoneData(const char *xmlPath); 83 static std::string ComputeLocale(std::string &locale); 84 icu::TimeZone* GetTimeZone(); 85 static std::string FindCityDisplayNameFromXml(std::string &cityID, std::string &locale); 86 static bool GetSupportedLocales(); 87 static std::string GetFallBack(std::string &localeStr); 88 static void GetTimezoneIDFromZoneInfo(std::set<std::string> &availableIDs, std::string &parentPath, 89 std::string &parentName); 90 static std::vector<int> GetColorData(const int x, const int y, int actualHeight, std::string preferredPath); 91 static int InitPngptr(png_structp &png_ptr, png_infop &info_ptr, FILE **fp, std::string preferredPath); 92 static std::vector<std::string> FindTzData(); 93 static bool ParamExceedScope(const int x, const int y, int fixedX, int fixedY); 94 static std::string GetPreferredPath(const double x, const std::vector<std::string> &filePaths); 95 static void SetVersionPathMap(std::string verison, std::string path, 96 std::map<std::string, std::vector<std::string>> *pathMap); 97 static void GetTzDataWidth(std::vector<std::string> filePaths, uint32_t *width, uint32_t *height); 98 static void CloseFile(FILE *fp); 99 static bool ValidateDataIntegrity(const std::vector<std::string> &pathList); 100 static bool CheckTzDataFilePath(const std::string &filePath); 101 }; 102 } // namespace I18n 103 } // namespace Global 104 } // namespace OHOS 105 #endif