/* * Copyright (c) 2021-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. */ #ifndef OHOS_GLOBAL_I18N_RELATIVE_TIME_FORMAT_H #define OHOS_GLOBAL_I18N_RELATIVE_TIME_FORMAT_H #include #include #include #include #include "unicode/numberformatter.h" #include "unicode/locid.h" #include "unicode/numfmt.h" #include "unicode/unum.h" #include "unicode/decimfmt.h" #include "unicode/localebuilder.h" #include "unicode/numsys.h" #include "unicode/measfmt.h" #include "unicode/measunit.h" #include "unicode/measure.h" #include "unicode/currunit.h" #include "unicode/fmtable.h" #include "unicode/reldatefmt.h" #include "unicode/uformattedvalue.h" #include "unicode/ures.h" #include "unicode/unum.h" #include "unicode/ulocdata.h" #include "unicode/ureldatefmt.h" #include "number_utils.h" #include "number_utypes.h" #include "locale_info.h" #include "measure_data.h" namespace OHOS { namespace Global { namespace I18n { class RelativeTimeFormat { public: RelativeTimeFormat(const std::vector &localeTag, std::map &configs); virtual ~RelativeTimeFormat(); std::string Format(double number, const std::string &unit); void FormatToParts(double number, const std::string &unit, std::vector> &timeVector); void GetResolvedOptions(std::map &map); private: icu::Locale locale; std::string localeBaseName; std::string styleString = "long"; std::string numeric = "always"; std::string numberingSystem; std::unique_ptr localeInfo; std::unique_ptr relativeTimeFormat; UDateRelativeDateTimeFormatterStyle style = UDAT_STYLE_LONG; bool createSuccess = false; static const char *DEVICE_TYPE_NAME; static const int BUFFER_LEN = 10; static std::unordered_map relativeUnits; static std::unordered_map relativeFormatStyle; static std::unordered_map defaultFormatStyle; void InsertInfo(std::vector> &timeVector, const std::string &unit, bool isInteger, const std::string &value); void ProcessIntegerField(const std::map &indexMap, std::vector> &timeVector, size_t &startIndex, const std::string &unit, const std::string &result); void ParseConfigs(std::map &configs); void SetDefaultStyle(); }; } // namespace I18n } // namespace Global } // namespace OHOS #endif