#include "src/objects/js-date-time-format.h"
#include <algorithm>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "src/base/bit-field.h"
#include "src/date/date.h"
#include "src/execution/isolate.h"
#include "src/heap/factory.h"
#include "src/objects/intl-objects.h"
#include "src/objects/js-date-time-format-inl.h"
#include "src/objects/js-temporal-objects-inl.h"
#include "src/objects/managed-inl.h"
#include "src/objects/option-utils.h"
#include "unicode/calendar.h"
#include "unicode/dtitvfmt.h"
#include "unicode/dtptngen.h"
#include "unicode/fieldpos.h"
#include "unicode/gregocal.h"
#include "unicode/smpdtfmt.h"
#include "unicode/unistr.h"
#ifndef V8_INTL_SUPPORT
#error Internationalization is expected to be enabled.
#endif
namespace v8::internal {
namespace …
std::string JSDateTimeFormat::CanonicalizeTimeZoneID(const std::string& input) { … }
namespace {
Handle<String> DateTimeStyleAsString(Isolate* isolate,
JSDateTimeFormat::DateTimeStyle style) { … }
int FractionalSecondDigitsFromPattern(const std::string& pattern) { … }
}
MaybeHandle<String> JSDateTimeFormat::TimeZoneIdToString(
Isolate* isolate, const icu::UnicodeString& id) { … }
Handle<Object> JSDateTimeFormat::TimeZoneId(Isolate* isolate,
const icu::TimeZone& tz) { … }
namespace {
Handle<String> GetCalendar(Isolate* isolate,
const icu::SimpleDateFormat& simple_date_format) { … }
Handle<Object> GetTimeZone(Isolate* isolate,
const icu::SimpleDateFormat& simple_date_format) { … }
}
Handle<String> JSDateTimeFormat::Calendar(
Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format) { … }
Handle<Object> JSDateTimeFormat::TimeZone(
Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format) { … }
MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions(
Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format) { … }
namespace {
bool IsTemporalObject(DirectHandle<Object> value) { … }
bool SameTemporalType(DirectHandle<Object> x, DirectHandle<Object> y) { … }
enum class PatternKind { … };
struct DateTimeValueRecord { … };
DateTimeValueRecord TemporalInstantToRecord(
Isolate* isolate, DirectHandle<JSTemporalInstant> instant,
PatternKind kind) { … }
Maybe<DateTimeValueRecord> TemporalPlainDateTimeToRecord(
Isolate* isolate, const icu::SimpleDateFormat& date_time_format,
PatternKind kind, Handle<JSTemporalPlainDateTime> plain_date_time,
const char* method_name) { … }
template <typename T>
Maybe<DateTimeValueRecord> TemporalToRecord(
Isolate* isolate, const icu::SimpleDateFormat& date_time_format,
PatternKind kind, Handle<T> temporal, Handle<JSReceiver> calendar,
const char* method_name) { … }
Maybe<DateTimeValueRecord> HandleDateTimeTemporalDate(
Isolate* isolate, const icu::SimpleDateFormat& date_time_format,
Handle<String> date_time_format_calendar,
Handle<JSTemporalPlainDate> temporal_date, const char* method_name) { … }
Maybe<DateTimeValueRecord> HandleDateTimeTemporalDateTime(
Isolate* isolate, const icu::SimpleDateFormat& date_time_format,
Handle<String> date_time_format_calendar,
Handle<JSTemporalPlainDateTime> date_time, const char* method_name) { … }
Maybe<DateTimeValueRecord> HandleDateTimeTemporalZonedDateTime(
Isolate* isolate, const icu::SimpleDateFormat& date_time_format,
Handle<String> date_time_format_calendar,
DirectHandle<JSTemporalZonedDateTime> zoned_date_time,
const char* method_name) { … }
Maybe<DateTimeValueRecord> HandleDateTimeTemporalInstant(
Isolate* isolate, const icu::SimpleDateFormat& date_time_format,
DirectHandle<JSTemporalInstant> instant, const char* method_name) { … }
Maybe<DateTimeValueRecord> HandleDateTimeTemporalTime(
Isolate* isolate, const icu::SimpleDateFormat& date_time_format,
DirectHandle<JSTemporalPlainTime> temporal_time, const char* method_name) { … }
template <typename T>
Maybe<DateTimeValueRecord> HandleDateTimeTemporalYearMonthOrMonthDay(
Isolate* isolate, const icu::SimpleDateFormat& date_time_format,
Handle<String> date_time_format_calendar, PatternKind kind,
Handle<T> temporal, const char* method_name) { … }
Maybe<DateTimeValueRecord> HandleDateTimeTemporalYearMonth(
Isolate* isolate, const icu::SimpleDateFormat& date_time_format,
Handle<String> date_time_format_calendar,
Handle<JSTemporalPlainYearMonth> temporal_year_month,
const char* method_name) { … }
Maybe<DateTimeValueRecord> HandleDateTimeTemporalMonthDay(
Isolate* isolate, const icu::SimpleDateFormat& date_time_format,
Handle<String> date_time_format_calendar,
Handle<JSTemporalPlainMonthDay> temporal_month_day,
const char* method_name) { … }
Maybe<DateTimeValueRecord> HandleDateTimeOthers(
Isolate* isolate, const icu::SimpleDateFormat& date_time_format,
Handle<Object> x_obj, const char* method_name) { … }
Maybe<DateTimeValueRecord> HandleDateTimeValue(
Isolate* isolate, const icu::SimpleDateFormat& date_time_format,
Handle<String> date_time_format_calendar, Handle<Object> x,
const char* method_name) { … }
icu::UnicodeString KeepSupportedAddDefault(
const icu::UnicodeString& input, const std::set<char16_t>& keep,
const std::set<char16_t>& add_default) { … }
icu::UnicodeString GetSkeletonForPatternKind(const icu::UnicodeString& input,
PatternKind kind) { … }
icu::UnicodeString SkeletonFromDateFormat(
const icu::SimpleDateFormat& icu_date_format) { … }
std::unique_ptr<icu::SimpleDateFormat> GetSimpleDateTimeForTemporal(
const icu::SimpleDateFormat& date_format, PatternKind kind) { … }
icu::UnicodeString CallICUFormat(const icu::SimpleDateFormat& date_format,
PatternKind kind, double time_in_milliseconds,
icu::FieldPositionIterator* fp_iter,
UErrorCode& status) { … }
MaybeHandle<String> FormatDateTime(Isolate* isolate,
const icu::SimpleDateFormat& date_format,
double x) { … }
MaybeHandle<String> FormatMillisecondsByKindToString(
Isolate* isolate, const icu::SimpleDateFormat& date_format,
PatternKind kind, double x) { … }
MaybeHandle<String> FormatDateTimeWithTemporalSupport(
Isolate* isolate, const icu::SimpleDateFormat& date_format,
Handle<String> date_time_format_calendar, Handle<Object> x,
const char* method_name) { … }
MaybeHandle<String> FormatDateTimeWithTemporalSupport(
Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format,
Handle<Object> x, const char* method_name) { … }
}
MaybeHandle<String> JSDateTimeFormat::DateTimeFormat(
Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format,
Handle<Object> date, const char* method_name) { … }
namespace {
Isolate::ICUObjectCacheType ConvertToCacheType(
JSDateTimeFormat::DefaultsOption type) { … }
}
MaybeHandle<String> JSDateTimeFormat::ToLocaleDateTime(
Isolate* isolate, Handle<Object> date, Handle<Object> locales,
Handle<Object> options, RequiredOption required, DefaultsOption defaults,
const char* method_name) { … }
MaybeHandle<String> JSDateTimeFormat::TemporalToLocaleString(
Isolate* isolate, Handle<JSReceiver> x, Handle<Object> locales,
Handle<Object> options, const char* method_name) { … }
MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::UnwrapDateTimeFormat(
Isolate* isolate, Handle<JSReceiver> format_holder) { … }
std::optional<std::string> GetOffsetTimeZone(Isolate* isolate,
Handle<String> time_zone) { … }
std::unique_ptr<icu::TimeZone> JSDateTimeFormat::CreateTimeZone(
Isolate* isolate, Handle<String> time_zone_string) { … }
namespace {
class CalendarCache { … };
icu::Calendar* CreateCalendar(Isolate* isolate, const icu::Locale& icu_locale,
icu::TimeZone* tz) { … }
icu::UnicodeString ReplaceHourCycleInPattern(icu::UnicodeString pattern,
JSDateTimeFormat::HourCycle hc) { … }
std::unique_ptr<icu::SimpleDateFormat> CreateICUDateFormat(
const icu::Locale& icu_locale, const icu::UnicodeString& skeleton,
icu::DateTimePatternGenerator* generator, JSDateTimeFormat::HourCycle hc) { … }
class DateFormatCache { … };
std::unique_ptr<icu::SimpleDateFormat> CreateICUDateFormatFromCache(
const icu::Locale& icu_locale, const icu::UnicodeString& skeleton,
icu::DateTimePatternGenerator* generator, JSDateTimeFormat::HourCycle hc) { … }
std::unique_ptr<icu::DateIntervalFormat> LazyCreateDateIntervalFormat(
Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format,
PatternKind kind) { … }
JSDateTimeFormat::HourCycle HourCycleFromPattern(
const icu::UnicodeString pattern) { … }
icu::DateFormat::EStyle DateTimeStyleToEStyle(
JSDateTimeFormat::DateTimeStyle style) { … }
icu::UnicodeString ReplaceSkeleton(const icu::UnicodeString input,
JSDateTimeFormat::HourCycle hc) { … }
std::unique_ptr<icu::SimpleDateFormat> DateTimeStylePattern(
JSDateTimeFormat::DateTimeStyle date_style,
JSDateTimeFormat::DateTimeStyle time_style, icu::Locale& icu_locale,
JSDateTimeFormat::HourCycle hc, icu::DateTimePatternGenerator* generator) { … }
class DateTimePatternGeneratorCache { … };
}
enum FormatMatcherOption { … };
MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New(
Isolate* isolate, DirectHandle<Map> map, Handle<Object> locales,
Handle<Object> input_options, const char* service) { … }
MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::CreateDateTimeFormat(
Isolate* isolate, DirectHandle<Map> map, Handle<Object> locales,
Handle<Object> input_options, RequiredOption required,
DefaultsOption defaults, const char* service) { … }
namespace {
Handle<String> IcuDateFieldIdToDateType(int32_t field_id, Isolate* isolate) { … }
MaybeHandle<JSArray> FieldPositionIteratorToArray(
Isolate* isolate, const icu::UnicodeString& formatted,
icu::FieldPositionIterator fp_iter, bool output_source);
MaybeHandle<JSArray> FormatMillisecondsByKindToArray(
Isolate* isolate, const icu::SimpleDateFormat& date_format,
PatternKind kind, double x, bool output_source) { … }
MaybeHandle<JSArray> FormatMillisecondsByKindToArrayOutputSource(
Isolate* isolate, const icu::SimpleDateFormat& date_format,
PatternKind kind, double x) { … }
MaybeHandle<JSArray> FormatToPartsWithTemporalSupport(
Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format,
Handle<Object> x, bool output_source, const char* method_name) { … }
MaybeHandle<JSArray> FormatMillisecondsToArray(
Isolate* isolate, const icu::SimpleDateFormat& format, double value,
bool output_source) { … }
MaybeHandle<JSArray> FormatMillisecondsToArrayOutputSource(
Isolate* isolate, const icu::SimpleDateFormat& format, double value) { … }
}
MaybeHandle<JSArray> JSDateTimeFormat::FormatToParts(
Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format,
Handle<Object> x, bool output_source, const char* method_name) { … }
namespace {
MaybeHandle<JSArray> FieldPositionIteratorToArray(
Isolate* isolate, const icu::UnicodeString& formatted,
icu::FieldPositionIterator fp_iter, bool output_source) { … }
}
const std::set<std::string>& JSDateTimeFormat::GetAvailableLocales() { … }
Handle<String> JSDateTimeFormat::HourCycleAsString() const { … }
namespace {
Maybe<bool> AddPartForFormatRange(
Isolate* isolate, Handle<JSArray> array, const icu::UnicodeString& string,
int32_t index, int32_t field, int32_t start, int32_t end,
const Intl::FormatRangeSourceTracker& tracker) { … }
std::optional<MaybeHandle<String>> FormattedToString(
Isolate* isolate, const icu::FormattedValue& formatted) { … }
std::optional<MaybeHandle<JSArray>> FormattedDateIntervalToJSArray(
Isolate* isolate, const icu::FormattedValue& formatted) { … }
template <typename T, std::optional<MaybeHandle<T>> (*Format)(
Isolate*, const icu::FormattedValue&)>
std::optional<MaybeHandle<T>> CallICUFormatRange(
Isolate* isolate, const icu::DateIntervalFormat* format,
const icu::Calendar* calendar, double x, double y);
template <typename T, std::optional<MaybeHandle<T>> (*Format)(
Isolate*, const icu::FormattedValue&)>
std::optional<MaybeHandle<T>> PartitionDateTimeRangePattern(
Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format, double x,
double y, const char* method_name) { … }
template <typename T, std::optional<MaybeHandle<T>> (*Format)(
Isolate*, const icu::FormattedValue&)>
std::optional<MaybeHandle<T>> CallICUFormatRange(
Isolate* isolate, const icu::DateIntervalFormat* format,
const icu::Calendar* calendar, double x, double y) { … }
template <typename T,
std::optional<MaybeHandle<T>> (*Format)(Isolate*,
const icu::FormattedValue&),
MaybeHandle<T> (*Fallback)(Isolate*, const icu::SimpleDateFormat&,
PatternKind, double)>
MaybeHandle<T> FormatRangeCommonWithTemporalSupport(
Isolate* isolate, DirectHandle<JSDateTimeFormat> date_time_format,
Handle<Object> x_obj, Handle<Object> y_obj, const char* method_name) { … }
template <typename T,
std::optional<MaybeHandle<T>> (*Format)(Isolate*,
const icu::FormattedValue&),
MaybeHandle<T> (*Fallback)(Isolate*, const icu::SimpleDateFormat&,
double)>
MaybeHandle<T> FormatRangeCommon(Isolate* isolate,
Handle<JSDateTimeFormat> date_time_format,
Handle<Object> x_obj, Handle<Object> y_obj,
const char* method_name) { … }
}
MaybeHandle<String> JSDateTimeFormat::FormatRange(
Isolate* isolate, Handle<JSDateTimeFormat> date_time_format,
Handle<Object> x, Handle<Object> y, const char* method_name) { … }
MaybeHandle<JSArray> JSDateTimeFormat::FormatRangeToParts(
Isolate* isolate, Handle<JSDateTimeFormat> date_time_format,
Handle<Object> x, Handle<Object> y, const char* method_name) { … }
}