1 /* 2 * Copyright (c) 2021-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 I18N_TIMEZONE_ADDON_H 16 #define I18N_TIMEZONE_ADDON_H 17 18 #include "i18n_timezone.h" 19 #include "napi/native_api.h" 20 #include "napi/native_node_api.h" 21 22 namespace OHOS { 23 namespace Global { 24 namespace I18n { 25 class I18nTimeZoneAddon { 26 public: 27 I18nTimeZoneAddon(); 28 ~I18nTimeZoneAddon(); 29 static void Destructor(napi_env env, void *nativeObject, void *hint); 30 static napi_value GetI18nTimeZone(napi_env env, napi_callback_info info); 31 static napi_value InitI18nTimeZone(napi_env env, napi_value exports); 32 33 private: 34 static napi_value InitTimeZone(napi_env env, napi_value exports); 35 static napi_value I18nTimeZoneConstructor(napi_env env, napi_callback_info info); 36 static napi_value GetAvailableTimezoneIDs(napi_env env, napi_callback_info info); 37 static napi_value GetAvailableZoneCityIDs(napi_env env, napi_callback_info info); 38 static napi_value GetCityDisplayName(napi_env env, napi_callback_info info); 39 static napi_value GetTimezoneFromCity(napi_env env, napi_callback_info info); 40 static napi_value GetTimezonesByLocation(napi_env env, napi_callback_info info); 41 static bool CheckLongitudeTypeAndScope(napi_env env, napi_value argv, double &x); 42 static bool CheckLatitudeTypeAndScope(napi_env env, napi_value argv, double &y); 43 44 static napi_value GetID(napi_env env, napi_callback_info info); 45 static napi_value GetTimeZoneDisplayName(napi_env env, napi_callback_info info); 46 static napi_value GetRawOffset(napi_env env, napi_callback_info info); 47 static napi_value GetOffset(napi_env env, napi_callback_info info); 48 49 static napi_value StaticGetTimeZone(napi_env, napi_value *argv, bool isZoneID); 50 static int32_t GetParameter(napi_env env, napi_value *argv, std::string &localeStr, bool &isDST); 51 static bool GetStringFromJS(napi_env env, napi_value argv, std::string &jsString); 52 static int32_t GetFirstParameter(napi_env env, napi_value value, std::string &localeStr, bool &isDST); 53 54 std::unique_ptr<I18nTimeZone> timezone_ = nullptr; 55 }; 56 } // namespace I18n 57 } // namespace Global 58 } // namespace OHOS 59 #endif