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 <stdint.h> 19 #include <map> 20 #include <set> 21 #include <string> 22 #include <vector> 23 24 #include "memory" 25 #include "unicode/timezone.h" 26 27 namespace OHOS { 28 namespace Global { 29 namespace I18n { 30 class I18nTimeZone { 31 public: 32 I18nTimeZone(std::string &id, bool isZoneID); 33 ~I18nTimeZone(); 34 int32_t GetOffset(double date); 35 int32_t GetRawOffset(); 36 std::string GetID(); 37 std::string GetDisplayName(); 38 std::string GetDisplayName(bool isDST); 39 std::string GetDisplayName(std::string localeStr); 40 std::string GetDisplayName(std::string localeStr, bool isDST); 41 static std::unique_ptr<I18nTimeZone> CreateInstance(std::string &id, bool isZoneID); 42 static std::set<std::string> GetAvailableIDs(); 43 static std::vector<std::string> GetAvailableZoneCityIDs(); 44 static std::string GetCityDisplayName(std::string &cityID, std::string &locale); 45 46 private: 47 static const char *TIMEZONE_KEY; 48 static const char *DEFAULT_TIMEZONE; 49 static const char *DEFAULT_LANGUAGE; 50 static const char *DEFAULT_LOCALE; 51 static const char *TIMEZONES_PATH; 52 static const char *SUPPORT_LOCALES_PATH; 53 static const char *rootTag; 54 static const char *secondRootTag; 55 static const uint32_t ELEMENT_NUM = 3; 56 static const char *supportLocalesTag; 57 static std::string displayLocale; 58 static bool isInitialized; 59 static std::set<std::string> availableIDs; 60 static std::vector<std::string> availableZoneCityIDs; 61 static std::map<std::string, std::string> city2DisplayName; 62 static std::map<std::string, std::string> city2TimeZoneID; 63 static std::map<std::string, std::string> supportLocales; 64 static constexpr int SYS_PARAM_LEN = 128; 65 icu::TimeZone *timezone = nullptr; 66 67 static void ReadTimeZoneData(const char *xmlPath); 68 static std::string ComputeLocale(std::string &locale); 69 icu::TimeZone* GetTimeZone(); 70 }; 71 } // namespace I18n 72 } // namespace Global 73 } // namespace OHOS 74 #endif