-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement DateTimeFormat.format for non android/ios environments (#1362)
Summary: Related to #1350 and #1211 Follow up of #1361 I'd like to expand non iOS/android support of `Intl`. In this case, I'm implementing both `DateTimeFormat.prototype.resolvedOptions` and `DateTimeFormat.prototype.format`. The implementation is a mix from the Apple and hermes-windows' implementations. - created `PlatformIntlShared` with helper functions that are exactly the same between Apple and ICU - Implemented `DateTimeFormatICU` based on `DateTimeFormatApple` - Used an ICU equivalent whenever NS was used for Apple Pull Request resolved: #1362 Test Plan: Testing against `test262/test/intl402/DateTimeFormat` Reviewed By: tmikov Differential Revision: D55893825 Pulled By: neildhar fbshipit-source-id: 03eef39721915ef03ebf6859980c374e10d337e9
- Loading branch information
1 parent
d00fe80
commit 042024c
Showing
4 changed files
with
1,538 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#ifndef HERMES_PLATFORMINTL_PLATFORMINTLSHARED_H | ||
#define HERMES_PLATFORMINTL_PLATFORMINTLSHARED_H | ||
|
||
#ifdef HERMES_ENABLE_INTL | ||
#include "hermes/Platform/Intl/PlatformIntl.h" | ||
|
||
namespace hermes { | ||
namespace platform_intl { | ||
|
||
struct LocaleMatch { | ||
std::u16string locale; | ||
std::map<std::u16string, std::u16string> extensions; | ||
}; | ||
|
||
struct ResolvedLocale { | ||
std::u16string locale; | ||
std::u16string dataLocale; | ||
std::unordered_map<std::u16string, std::u16string> extensions; | ||
}; | ||
|
||
/// https://402.ecma-international.org/8.0/#sec-canonicalizelocalelist | ||
vm::CallResult<std::vector<std::u16string>> canonicalizeLocaleList( | ||
vm::Runtime &runtime, | ||
const std::vector<std::u16string> &locales); | ||
|
||
/// https://402.ecma-international.org/8.0/#sec-intl.getcanonicallocales | ||
vm::CallResult<std::vector<std::u16string>> getCanonicalLocales( | ||
vm::Runtime &runtime, | ||
const std::vector<std::u16string> &locales); | ||
|
||
/// https://402.ecma-international.org/8.0/#sec-bestavailablelocale | ||
std::optional<std::u16string> bestAvailableLocale( | ||
const std::vector<std::u16string> &availableLocales, | ||
const std::u16string &locale); | ||
|
||
/// https://402.ecma-international.org/8.0/#sec-lookupsupportedlocales | ||
std::vector<std::u16string> lookupSupportedLocales( | ||
const std::vector<std::u16string> &availableLocales, | ||
const std::vector<std::u16string> &requestedLocales); | ||
|
||
/// https://402.ecma-international.org/8.0/#sec-supportedlocales | ||
std::vector<std::u16string> supportedLocales( | ||
const std::vector<std::u16string> &availableLocales, | ||
const std::vector<std::u16string> &requestedLocales); | ||
|
||
/// https://402.ecma-international.org/8.0/#sec-getoption | ||
vm::CallResult<std::optional<std::u16string>> getOptionString( | ||
vm::Runtime &runtime, | ||
const Options &options, | ||
const std::u16string &property, | ||
llvh::ArrayRef<std::u16string_view> values, | ||
std::optional<std::u16string_view> fallback); | ||
|
||
/// https://402.ecma-international.org/8.0/#sec-getoption | ||
std::optional<bool> getOptionBool( | ||
vm::Runtime &runtime, | ||
const Options &options, | ||
const std::u16string &property, | ||
std::optional<bool> fallback); | ||
|
||
/// https://402.ecma-international.org/8.0/#sec-todatetimeoptions | ||
vm::CallResult<Options> toDateTimeOptions( | ||
vm::Runtime &runtime, | ||
Options options, | ||
std::u16string_view required, | ||
std::u16string_view defaults); | ||
|
||
/// https://402.ecma-international.org/8.0/#sec-case-sensitivity-and-case-mapping | ||
std::u16string toASCIIUppercase(std::u16string_view tz); | ||
|
||
/// https://402.ecma-international.org/8.0/#sec-defaultnumberoption | ||
vm::CallResult<std::optional<uint8_t>> defaultNumberOption( | ||
vm::Runtime &runtime, | ||
const std::u16string &property, | ||
std::optional<Option> value, | ||
const std::uint8_t minimum, | ||
const std::uint8_t maximum, | ||
std::optional<uint8_t> fallback); | ||
|
||
/// https://402.ecma-international.org/8.0/#sec-getoption | ||
vm::CallResult<std::optional<uint8_t>> getNumberOption( | ||
vm::Runtime &runtime, | ||
const Options &options, | ||
const std::u16string &property, | ||
const std::uint8_t minimum, | ||
const std::uint8_t maximum, | ||
std::optional<uint8_t> fallback); | ||
} // namespace platform_intl | ||
} // namespace hermes | ||
|
||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.