#ifndef V8_INTL_SUPPORT
#error Internationalization is expected to be enabled.
#endif
#include "src/objects/js-relative-time-format.h"
#include <map>
#include <memory>
#include <string>
#include "src/execution/isolate.h"
#include "src/heap/factory.h"
#include "src/objects/intl-objects.h"
#include "src/objects/js-number-format.h"
#include "src/objects/js-relative-time-format-inl.h"
#include "src/objects/managed-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/option-utils.h"
#include "unicode/decimfmt.h"
#include "unicode/numfmt.h"
#include "unicode/reldatefmt.h"
#include "unicode/unum.h"
namespace v8 {
namespace internal {
namespace {
enum class Style { … };
UDateRelativeDateTimeFormatterStyle toIcuStyle(Style style) { … }
Style fromIcuStyle(UDateRelativeDateTimeFormatterStyle icu_style) { … }
}
MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New(
Isolate* isolate, DirectHandle<Map> map, Handle<Object> locales,
Handle<Object> input_options) { … }
namespace {
Handle<String> StyleAsString(Isolate* isolate, Style style) { … }
}
Handle<JSObject> JSRelativeTimeFormat::ResolvedOptions(
Isolate* isolate, DirectHandle<JSRelativeTimeFormat> format_holder) { … }
Handle<String> JSRelativeTimeFormat::NumericAsString() const { … }
namespace {
Handle<String> UnitAsString(Isolate* isolate, URelativeDateTimeUnit unit_enum) { … }
bool GetURelativeDateTimeUnit(DirectHandle<String> unit,
URelativeDateTimeUnit* unit_enum) { … }
template <typename T>
MaybeHandle<T> FormatCommon(
Isolate* isolate, DirectHandle<JSRelativeTimeFormat> format,
Handle<Object> value_obj, Handle<Object> unit_obj, const char* func_name,
MaybeHandle<T> (*formatToResult)(Isolate*,
const icu::FormattedRelativeDateTime&,
DirectHandle<String>, bool)) { … }
MaybeHandle<String> FormatToString(
Isolate* isolate, const icu::FormattedRelativeDateTime& formatted,
DirectHandle<String> unit, bool is_nan) { … }
Maybe<bool> AddLiteral(Isolate* isolate, Handle<JSArray> array,
const icu::UnicodeString& string, int32_t index,
int32_t start, int32_t limit) { … }
Maybe<bool> AddUnit(Isolate* isolate, Handle<JSArray> array,
const icu::UnicodeString& string, int32_t index,
const NumberFormatSpan& part, DirectHandle<String> unit,
bool is_nan) { … }
MaybeHandle<JSArray> FormatToJSArray(
Isolate* isolate, const icu::FormattedRelativeDateTime& formatted,
DirectHandle<String> unit, bool is_nan) { … }
}
MaybeHandle<String> JSRelativeTimeFormat::Format(
Isolate* isolate, Handle<Object> value_obj, Handle<Object> unit_obj,
DirectHandle<JSRelativeTimeFormat> format) { … }
MaybeHandle<JSArray> JSRelativeTimeFormat::FormatToParts(
Isolate* isolate, Handle<Object> value_obj, Handle<Object> unit_obj,
DirectHandle<JSRelativeTimeFormat> format) { … }
const std::set<std::string>& JSRelativeTimeFormat::GetAvailableLocales() { … }
}
}