diff --git a/global/i18n/BUILD.gn b/global/i18n/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4068226a9b909f454b4bc8e73e4cdbf461f35c4c --- /dev/null +++ b/global/i18n/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +ohos_ndk_library("native_i18n_ndk") { + ndk_description_file = "./libnative_i18n.ndk.json" + min_compact_version = "20" + output_name = "ohi18n" + output_extension = "so" + system_capability = "SystemCapability.Global.I18n" + system_capability_headers = [ + "i18n/i18n_errorcode.h", + "i18n/i18n_timezone.h", + ] +} + +ohos_ndk_headers("native_i18n_header") { + dest_dir = "$ndk_headers_out_dir/i18n" + sources = [ + "./include/i18n_errorcode.h", + "./include/i18n_timezone.h", + ] +} diff --git a/global/i18n/include/i18n_errorcode.h b/global/i18n/include/i18n_errorcode.h new file mode 100644 index 0000000000000000000000000000000000000000..1fafb01959d00ee1d6c5ee65e36332c3256805cd --- /dev/null +++ b/global/i18n/include/i18n_errorcode.h @@ -0,0 +1,17 @@ +#ifndef GLOBAL_I18N_ERRORCODE_H +#define GLOBAL_I18N_ERRORCODE_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum I18N_ErrorCode { + SUCCESS = 0, + ERROR_CODE_INVALID_PARAMETER = 8900001, + ERROR_CODE_OUT_OF_MEMORY = 8900002, +} I18N_ErrorCode; + +#ifdef __cplusplus +}; +#endif +#endif \ No newline at end of file diff --git a/global/i18n/include/i18n_timezone.h b/global/i18n/include/i18n_timezone.h new file mode 100644 index 0000000000000000000000000000000000000000..e2ebc57a53dd4ad1f45bf9ceac34cc93cd1b0e6f --- /dev/null +++ b/global/i18n/include/i18n_timezone.h @@ -0,0 +1,101 @@ +#ifndef GLOBAL_I18N_TIMEZONE_H +#define GLOBAL_I18N_TIMEZONE_H + +#include +#include +#include "i18n_errorcode.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum DateRuleType { + DOM = 0, + DOW = 1, + DOW_GEQ_DOM = 2, + DOW_LEQ_DOM = 3 +} DateRuleType; + +typedef enum TimeRuleType { + WALL_TIME = 0, + STANDARD_TIME = 1, + UTC_TIME = 2, +} TimeRuleType; + +typedef struct DateTimeRule { + int32_t month; + int32_t dayOfMonth; + int32_t dayOfWeek; + int32_t weekInMonth; + int32_t millisInDay; + DateRuleType dateRuleType; + TimeRuleType timeRuleType; +} DateTimeRule; + +typedef struct InitialTimeZoneRule { + int32_t rawOffset; + int32_t dstSavings; +} InitialTimeZoneRule; + +typedef struct TimeArrayTimeZoneRule { + char* name; + int32_t rawOffset; + int32_t dstSavings; + double* startTimes; + int32_t numStartTimes; + TimeRuleType timeRuleType; +} TimeArrayTimeZoneRule; + +#define MAX_YEAR_VALUE 0x7fffffff + +typedef struct AnnualTimeZoneRule { + char* name; + int32_t startYear; + int32_t endYear; + int32_t rawOffset; + int32_t dstSavings; + DateTimeRule dateTimeRule; +} AnnualTimeZoneRule; + +typedef struct TimeZoneRules { + InitialTimeZoneRule initial; + TimeArrayTimeZoneRule* timeArrayRules; + AnnualTimeZoneRule* annualRules; + size_t numTimeArrayRules; + size_t numAnnualRules; +} TimeZoneRules; + +I18N_ErrorCode OH_i18n_GetTimeZoneRules(const char* timeZoneID, TimeZoneRules* rules); + +typedef struct TimeZoneRuleQuery { + double base; + int32_t prevRawOffset; + int32_t prevDSTSavings; + bool inclusive; + double result; +} TimeZoneRuleQuery; + +I18N_ErrorCode OH_i18n_GetFirstStartFromTimeArrayTimeZoneRule(TimeArrayTimeZoneRule* rule, TimeZoneRuleQuery* query); + +I18N_ErrorCode OH_i18n_GetFirstStartFromAnnualTimeZoneRule(AnnualTimeZoneRule* rule, TimeZoneRuleQuery* query); + +I18N_ErrorCode OH_i18n_GetFinalStartFromTimeArrayTimeZoneRule(TimeArrayTimeZoneRule* rule, TimeZoneRuleQuery* query); + +I18N_ErrorCode OH_i18n_GetFinalStartFromAnnualTimeZoneRule(AnnualTimeZoneRule* rule, TimeZoneRuleQuery* query); + +I18N_ErrorCode OH_i18n_GetNextStartFromTimeArrayTimeZoneRule(TimeArrayTimeZoneRule* rule, TimeZoneRuleQuery* query); + +I18N_ErrorCode OH_i18n_GetNextStartFromAnnualTimeZoneRule(AnnualTimeZoneRule* rule, TimeZoneRuleQuery* query); + +I18N_ErrorCode OH_i18n_GetPrevStartFromTimeArrayTimeZoneRule(TimeArrayTimeZoneRule* rule, TimeZoneRuleQuery* query); + +I18N_ErrorCode OH_i18n_GetPrevStartFromAnnualTimeZoneRule(AnnualTimeZoneRule* rule, TimeZoneRuleQuery* query); + +I18N_ErrorCode OH_i18n_GetStartTimeAt(TimeArrayTimeZoneRule* rule, int32_t index, double* result); + +I18N_ErrorCode OH_i18n_GetStartInYear(AnnualTimeZoneRule* rule, int32_t year, TimeZoneRuleQuery* query); + +#ifdef __cplusplus +}; +#endif +#endif \ No newline at end of file diff --git a/global/i18n/libnative_i18n.ndk.json b/global/i18n/libnative_i18n.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..79fdb3a8667e366ea1a26dd4a861c6cdd3e92348 --- /dev/null +++ b/global/i18n/libnative_i18n.ndk.json @@ -0,0 +1,46 @@ +[ + { + "first_introduced": "20", + "name": "OH_i18n_GetTimeZoneRules" + }, + { + "first_introduced": "20", + "name": "OH_i18n_GetFirstStartFromTimeArrayTimeZoneRule" + }, + { + "first_introduced": "20", + "name": "OH_i18n_GetFirstStartFromAnnualTimeZoneRule" + }, + { + "first_introduced": "20", + "name": "OH_i18n_GetFinalStartFromTimeArrayTimeZoneRule" + }, + { + "first_introduced": "20", + "name": "OH_i18n_GetFinalStartFromAnnualTimeZoneRule" + }, + { + "first_introduced": "20", + "name": "OH_i18n_GetNextStartFromTimeArrayTimeZoneRule" + }, + { + "first_introduced": "20", + "name": "OH_i18n_GetNextStartFromAnnualTimeZoneRule" + }, + { + "first_introduced": "20", + "name": "OH_i18n_GetPrevStartFromTimeArrayTimeZoneRule" + }, + { + "first_introduced": "20", + "name": "OH_i18n_GetPrevStartFromAnnualTimeZoneRule" + }, + { + "first_introduced": "20", + "name": "OH_i18n_GetStartTimeAt" + }, + { + "first_introduced": "20", + "name": "OH_i18n_GetStartInYear" + } +] \ No newline at end of file diff --git a/ndk_targets.gni b/ndk_targets.gni index 987a50607c26300ef3478c548085d61cf4fbbfc4..ea61d4d956ab3bb55e51e75f063f00346dd5ab63 100644 --- a/ndk_targets.gni +++ b/ndk_targets.gni @@ -23,6 +23,8 @@ _ndk_library_targets = [ "//interface/sdk_c/global/resource_management:rawfile_header", "//interface/sdk_c/global/resource_management:native_resmgr_ndk", "//interface/sdk_c/global/resource_management:native_resmgr_header", + "//interface/sdk_c/global/i18n:native_i18n_ndk", + "//interface/sdk_c/global/i18n:native_i18n_header", "//interface/sdk_c/hiviewdfx/hiappevent:libhiappevent_header", "//interface/sdk_c/hiviewdfx/hiappevent:libhiappevent_ndk", "//interface/sdk_c/hiviewdfx/hidebug:libohhidebug",