DateTimeFormatConstructor.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /*
  2. * Copyright (c) 2021-2023, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/AbstractOperations.h>
  7. #include <LibJS/Runtime/Array.h>
  8. #include <LibJS/Runtime/Date.h>
  9. #include <LibJS/Runtime/GlobalObject.h>
  10. #include <LibJS/Runtime/Intl/AbstractOperations.h>
  11. #include <LibJS/Runtime/Intl/DateTimeFormat.h>
  12. #include <LibJS/Runtime/Intl/DateTimeFormatConstructor.h>
  13. #include <LibJS/Runtime/Temporal/TimeZone.h>
  14. #include <LibLocale/DateTimeFormat.h>
  15. #include <LibLocale/Locale.h>
  16. namespace JS::Intl {
  17. // 11.1 The Intl.DateTimeFormat Constructor, https://tc39.es/ecma402/#sec-intl-datetimeformat-constructor
  18. DateTimeFormatConstructor::DateTimeFormatConstructor(Realm& realm)
  19. : NativeFunction(realm.vm().names.DateTimeFormat.as_string(), realm.intrinsics().function_prototype())
  20. {
  21. }
  22. void DateTimeFormatConstructor::initialize(Realm& realm)
  23. {
  24. Base::initialize(realm);
  25. auto& vm = this->vm();
  26. // 11.2.1 Intl.DateTimeFormat.prototype, https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype
  27. define_direct_property(vm.names.prototype, realm.intrinsics().intl_date_time_format_prototype(), 0);
  28. u8 attr = Attribute::Writable | Attribute::Configurable;
  29. define_native_function(realm, vm.names.supportedLocalesOf, supported_locales_of, 1, attr);
  30. define_direct_property(vm.names.length, Value(0), Attribute::Configurable);
  31. }
  32. // 11.1.1 Intl.DateTimeFormat ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sec-intl.datetimeformat
  33. ThrowCompletionOr<Value> DateTimeFormatConstructor::call()
  34. {
  35. // 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
  36. return TRY(construct(*this));
  37. }
  38. // 11.1.1 Intl.DateTimeFormat ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sec-intl.datetimeformat
  39. ThrowCompletionOr<NonnullGCPtr<Object>> DateTimeFormatConstructor::construct(FunctionObject& new_target)
  40. {
  41. auto& vm = this->vm();
  42. auto locales = vm.argument(0);
  43. auto options = vm.argument(1);
  44. // 2. Let dateTimeFormat be ? CreateDateTimeFormat(newTarget, locales, options, any, date).
  45. auto date_time_format = TRY(create_date_time_format(vm, new_target, locales, options, OptionRequired::Any, OptionDefaults::Date));
  46. // 3. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
  47. // a. Let this be the this value.
  48. // b. Return ? ChainDateTimeFormat(dateTimeFormat, NewTarget, this).
  49. // 4. Return dateTimeFormat.
  50. return date_time_format;
  51. }
  52. // 11.2.2 Intl.DateTimeFormat.supportedLocalesOf ( locales [ , options ] ), https://tc39.es/ecma402/#sec-intl.datetimeformat.supportedlocalesof
  53. JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatConstructor::supported_locales_of)
  54. {
  55. auto locales = vm.argument(0);
  56. auto options = vm.argument(1);
  57. // 1. Let availableLocales be %DateTimeFormat%.[[AvailableLocales]].
  58. // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
  59. auto requested_locales = TRY(canonicalize_locale_list(vm, locales));
  60. // 3. Return ? SupportedLocales(availableLocales, requestedLocales, options).
  61. return TRY(supported_locales(vm, requested_locales, options));
  62. }
  63. // 11.1.2 CreateDateTimeFormat ( newTarget, locales, options, required, defaults ), https://tc39.es/ecma402/#sec-createdatetimeformat
  64. ThrowCompletionOr<NonnullGCPtr<DateTimeFormat>> create_date_time_format(VM& vm, FunctionObject& new_target, Value locales_value, Value options_value, OptionRequired required, OptionDefaults defaults)
  65. {
  66. // 1. Let dateTimeFormat be ? OrdinaryCreateFromConstructor(newTarget, "%DateTimeFormat.prototype%", « [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[DayPeriod]], [[Hour]], [[Minute]], [[Second]], [[FractionalSecondDigits]], [[TimeZoneName]], [[HourCycle]], [[DateStyle]], [[TimeStyle]], [[Pattern]], [[RangePatterns]], [[BoundFormat]] »).
  67. auto date_time_format = TRY(ordinary_create_from_constructor<DateTimeFormat>(vm, new_target, &Intrinsics::intl_date_time_format_prototype));
  68. // 2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
  69. auto requested_locales = TRY(canonicalize_locale_list(vm, locales_value));
  70. // 3. Set options to ? CoerceOptionsToObject(options).
  71. auto* options = TRY(coerce_options_to_object(vm, options_value));
  72. // 4. Let opt be a new Record.
  73. LocaleOptions opt {};
  74. // 5. Let matcher be ? GetOption(options, "localeMatcher", string, « "lookup", "best fit" », "best fit").
  75. auto matcher = TRY(get_option(vm, *options, vm.names.localeMatcher, OptionType::String, AK::Array { "lookup"sv, "best fit"sv }, "best fit"sv));
  76. // 6. Set opt.[[localeMatcher]] to matcher.
  77. opt.locale_matcher = matcher;
  78. // 7. Let calendar be ? GetOption(options, "calendar", string, empty, undefined).
  79. auto calendar = TRY(get_option(vm, *options, vm.names.calendar, OptionType::String, {}, Empty {}));
  80. // 8. If calendar is not undefined, then
  81. if (!calendar.is_undefined()) {
  82. // a. If calendar cannot be matched by the type Unicode locale nonterminal, throw a RangeError exception.
  83. if (!::Locale::is_type_identifier(calendar.as_string().utf8_string_view()))
  84. return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, calendar, "calendar"sv);
  85. // 9. Set opt.[[ca]] to calendar.
  86. opt.ca = calendar.as_string().utf8_string();
  87. }
  88. // 10. Let numberingSystem be ? GetOption(options, "numberingSystem", string, empty, undefined).
  89. auto numbering_system = TRY(get_option(vm, *options, vm.names.numberingSystem, OptionType::String, {}, Empty {}));
  90. // 11. If numberingSystem is not undefined, then
  91. if (!numbering_system.is_undefined()) {
  92. // a. If numberingSystem cannot be matched by the type Unicode locale nonterminal, throw a RangeError exception.
  93. if (!::Locale::is_type_identifier(numbering_system.as_string().utf8_string_view()))
  94. return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, numbering_system, "numberingSystem"sv);
  95. // 12. Set opt.[[nu]] to numberingSystem.
  96. opt.nu = numbering_system.as_string().utf8_string();
  97. }
  98. // 13. Let hour12 be ? GetOption(options, "hour12", boolean, empty, undefined).
  99. auto hour12 = TRY(get_option(vm, *options, vm.names.hour12, OptionType::Boolean, {}, Empty {}));
  100. // 14. Let hourCycle be ? GetOption(options, "hourCycle", string, « "h11", "h12", "h23", "h24" », undefined).
  101. auto hour_cycle = TRY(get_option(vm, *options, vm.names.hourCycle, OptionType::String, AK::Array { "h11"sv, "h12"sv, "h23"sv, "h24"sv }, Empty {}));
  102. // 15. If hour12 is not undefined, then
  103. if (!hour12.is_undefined()) {
  104. // a. Set hourCycle to null.
  105. hour_cycle = js_null();
  106. }
  107. // 16. Set opt.[[hc]] to hourCycle.
  108. if (!hour_cycle.is_nullish())
  109. opt.hc = hour_cycle.as_string().utf8_string();
  110. // 17. Let localeData be %DateTimeFormat%.[[LocaleData]].
  111. // 18. Let r be ResolveLocale(%DateTimeFormat%.[[AvailableLocales]], requestedLocales, opt, %DateTimeFormat%.[[RelevantExtensionKeys]], localeData).
  112. auto result = MUST_OR_THROW_OOM(resolve_locale(vm, requested_locales, opt, DateTimeFormat::relevant_extension_keys()));
  113. // 19. Set dateTimeFormat.[[Locale]] to r.[[locale]].
  114. date_time_format->set_locale(move(result.locale));
  115. // 20. Let resolvedCalendar be r.[[ca]].
  116. // 21. Set dateTimeFormat.[[Calendar]] to resolvedCalendar.
  117. if (result.ca.has_value())
  118. date_time_format->set_calendar(result.ca.release_value());
  119. // 22. Set dateTimeFormat.[[NumberingSystem]] to r.[[nu]].
  120. if (result.nu.has_value())
  121. date_time_format->set_numbering_system(result.nu.release_value());
  122. // 23. Let dataLocale be r.[[dataLocale]].
  123. auto data_locale = move(result.data_locale);
  124. // Non-standard, the data locale is needed for LibUnicode lookups while formatting.
  125. date_time_format->set_data_locale(data_locale);
  126. // 24. Let dataLocaleData be localeData.[[<dataLocale>]].
  127. // 25. Let hcDefault be dataLocaleData.[[hourCycle]].
  128. auto default_hour_cycle = TRY_OR_THROW_OOM(vm, ::Locale::get_default_regional_hour_cycle(data_locale));
  129. // Non-standard, default_hour_cycle will be empty if Unicode data generation is disabled.
  130. if (!default_hour_cycle.has_value()) {
  131. date_time_format->set_time_zone(TRY_OR_THROW_OOM(vm, String::from_utf8(default_time_zone())));
  132. return date_time_format;
  133. }
  134. Optional<::Locale::HourCycle> hour_cycle_value;
  135. // 26. If hour12 is true, then
  136. if (hour12.is_boolean() && hour12.as_bool()) {
  137. // a. If hcDefault is "h11" or "h23", let hc be "h11". Otherwise, let hc be "h12".
  138. if ((default_hour_cycle == ::Locale::HourCycle::H11) || (default_hour_cycle == ::Locale::HourCycle::H23))
  139. hour_cycle_value = ::Locale::HourCycle::H11;
  140. else
  141. hour_cycle_value = ::Locale::HourCycle::H12;
  142. }
  143. // 27. Else if hour12 is false, then
  144. else if (hour12.is_boolean() && !hour12.as_bool()) {
  145. // a. If hcDefault is "h11" or "h23", let hc be "h23". Otherwise, let hc be "h24".
  146. if ((default_hour_cycle == ::Locale::HourCycle::H11) || (default_hour_cycle == ::Locale::HourCycle::H23))
  147. hour_cycle_value = ::Locale::HourCycle::H23;
  148. else
  149. hour_cycle_value = ::Locale::HourCycle::H24;
  150. }
  151. // 28. Else,
  152. else {
  153. // a. Assert: hour12 is undefined.
  154. VERIFY(hour12.is_undefined());
  155. // b. Let hc be r.[[hc]].
  156. if (result.hc.has_value())
  157. hour_cycle_value = ::Locale::hour_cycle_from_string(*result.hc);
  158. // c. If hc is null, set hc to hcDefault.
  159. if (!hour_cycle_value.has_value())
  160. hour_cycle_value = default_hour_cycle;
  161. }
  162. // 29. Set dateTimeFormat.[[HourCycle]] to hc.
  163. if (hour_cycle_value.has_value())
  164. date_time_format->set_hour_cycle(*hour_cycle_value);
  165. // 30. Let timeZone be ? Get(options, "timeZone").
  166. auto time_zone_value = TRY(options->get(vm.names.timeZone));
  167. String time_zone;
  168. // 31. If timeZone is undefined, then
  169. if (time_zone_value.is_undefined()) {
  170. // a. Set timeZone to DefaultTimeZone().
  171. time_zone = TRY_OR_THROW_OOM(vm, String::from_utf8(default_time_zone()));
  172. }
  173. // 32. Else,
  174. else {
  175. // a. Set timeZone to ? ToString(timeZone).
  176. time_zone = TRY(time_zone_value.to_string(vm));
  177. // b. If IsAvailableTimeZoneName(timeZone) is false, then
  178. if (!Temporal::is_available_time_zone_name(time_zone)) {
  179. // i. Throw a RangeError exception.
  180. return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, time_zone, vm.names.timeZone);
  181. }
  182. // c. Set timeZone to CanonicalizeTimeZoneName(timeZone).
  183. time_zone = MUST_OR_THROW_OOM(Temporal::canonicalize_time_zone_name(vm, time_zone));
  184. }
  185. // 33. Set dateTimeFormat.[[TimeZone]] to timeZone.
  186. date_time_format->set_time_zone(move(time_zone));
  187. // 34. Let formatOptions be a new Record.
  188. ::Locale::CalendarPattern format_options {};
  189. // 35. Set formatOptions.[[hourCycle]] to hc.
  190. format_options.hour_cycle = hour_cycle_value;
  191. // 36. Let hasExplicitFormatComponents be false.
  192. // NOTE: Instead of using a boolean, we track any explicitly provided component name for nicer exception messages.
  193. PropertyKey const* explicit_format_component = nullptr;
  194. // 37. For each row of Table 6, except the header row, in table order, do
  195. TRY(for_each_calendar_field(vm, format_options, [&](auto& option, auto const& property, auto const& values) -> ThrowCompletionOr<void> {
  196. using ValueType = typename RemoveReference<decltype(option)>::ValueType;
  197. // a. Let prop be the name given in the Property column of the row.
  198. // b. If prop is "fractionalSecondDigits", then
  199. if constexpr (IsIntegral<ValueType>) {
  200. // i. Let value be ? GetNumberOption(options, "fractionalSecondDigits", 1, 3, undefined).
  201. auto value = TRY(get_number_option(vm, *options, property, 1, 3, {}));
  202. // d. Set formatOptions.[[<prop>]] to value.
  203. if (value.has_value()) {
  204. option = static_cast<ValueType>(value.value());
  205. // e. If value is not undefined, then
  206. // i. Set hasExplicitFormatComponents to true.
  207. explicit_format_component = &property;
  208. }
  209. }
  210. // c. Else,
  211. else {
  212. // i. Let values be a List whose elements are the strings given in the Values column of the row.
  213. // ii. Let value be ? GetOption(options, prop, string, values, undefined).
  214. auto value = TRY(get_option(vm, *options, property, OptionType::String, values, Empty {}));
  215. // d. Set formatOptions.[[<prop>]] to value.
  216. if (!value.is_undefined()) {
  217. option = ::Locale::calendar_pattern_style_from_string(value.as_string().utf8_string_view());
  218. // e. If value is not undefined, then
  219. // i. Set hasExplicitFormatComponents to true.
  220. explicit_format_component = &property;
  221. }
  222. }
  223. return {};
  224. }));
  225. // 38. Let matcher be ? GetOption(options, "formatMatcher", string, « "basic", "best fit" », "best fit").
  226. matcher = TRY(get_option(vm, *options, vm.names.formatMatcher, OptionType::String, AK::Array { "basic"sv, "best fit"sv }, "best fit"sv));
  227. // 39. Let dateStyle be ? GetOption(options, "dateStyle", string, « "full", "long", "medium", "short" », undefined).
  228. auto date_style = TRY(get_option(vm, *options, vm.names.dateStyle, OptionType::String, AK::Array { "full"sv, "long"sv, "medium"sv, "short"sv }, Empty {}));
  229. // 40. Set dateTimeFormat.[[DateStyle]] to dateStyle.
  230. if (!date_style.is_undefined())
  231. date_time_format->set_date_style(date_style.as_string().utf8_string_view());
  232. // 41. Let timeStyle be ? GetOption(options, "timeStyle", string, « "full", "long", "medium", "short" », undefined).
  233. auto time_style = TRY(get_option(vm, *options, vm.names.timeStyle, OptionType::String, AK::Array { "full"sv, "long"sv, "medium"sv, "short"sv }, Empty {}));
  234. // 42. Set dateTimeFormat.[[TimeStyle]] to timeStyle.
  235. if (!time_style.is_undefined())
  236. date_time_format->set_time_style(time_style.as_string().utf8_string_view());
  237. Optional<::Locale::CalendarPattern> best_format {};
  238. // 43. If dateStyle is not undefined or timeStyle is not undefined, then
  239. if (date_time_format->has_date_style() || date_time_format->has_time_style()) {
  240. // a. If hasExplicitFormatComponents is true, then
  241. if (explicit_format_component != nullptr) {
  242. // i. Throw a TypeError exception.
  243. return vm.throw_completion<TypeError>(ErrorType::IntlInvalidDateTimeFormatOption, *explicit_format_component, "dateStyle or timeStyle"sv);
  244. }
  245. // b. If required is date and timeStyle is not undefined, then
  246. if (required == OptionRequired::Date && !time_style.is_undefined()) {
  247. // i. Throw a TypeError exception.
  248. return vm.throw_completion<TypeError>(ErrorType::IntlInvalidDateTimeFormatOption, "timeStyle"sv, "date"sv);
  249. }
  250. // c. If required is time and dateStyle is not undefined, then
  251. if (required == OptionRequired::Time && !date_style.is_undefined()) {
  252. // i. Throw a TypeError exception.
  253. return vm.throw_completion<TypeError>(ErrorType::IntlInvalidDateTimeFormatOption, "dateStyle"sv, "time"sv);
  254. }
  255. // d. Let styles be dataLocaleData.[[styles]].[[<resolvedCalendar>]].
  256. // e. Let bestFormat be DateTimeStyleFormat(dateStyle, timeStyle, styles).
  257. best_format = MUST_OR_THROW_OOM(date_time_style_format(vm, data_locale, date_time_format));
  258. }
  259. // 44. Else,
  260. else {
  261. // a. Let needDefaults be true.
  262. bool needs_defaults = true;
  263. // b. If required is date or any, then
  264. if (required == OptionRequired::Date || required == OptionRequired::Any) {
  265. // i. For each property name prop of « "weekday", "year", "month", "day" », do
  266. auto check_property_value = [&](auto const& value) {
  267. // 1. Let value be formatOptions.[[<prop>]].
  268. // 2. If value is not undefined, let needDefaults be false.
  269. if (value.has_value())
  270. needs_defaults = false;
  271. };
  272. check_property_value(format_options.weekday);
  273. check_property_value(format_options.year);
  274. check_property_value(format_options.month);
  275. check_property_value(format_options.day);
  276. }
  277. // c. If required is time or any, then
  278. if (required == OptionRequired::Time || required == OptionRequired::Any) {
  279. // i. For each property name prop of « "dayPeriod", "hour", "minute", "second", "fractionalSecondDigits" », do
  280. auto check_property_value = [&](auto const& value) {
  281. // 1. Let value be formatOptions.[[<prop>]].
  282. // 2. If value is not undefined, let needDefaults be false.
  283. if (value.has_value())
  284. needs_defaults = false;
  285. };
  286. check_property_value(format_options.day_period);
  287. check_property_value(format_options.hour);
  288. check_property_value(format_options.minute);
  289. check_property_value(format_options.second);
  290. check_property_value(format_options.fractional_second_digits);
  291. }
  292. // d. If needDefaults is true and defaults is either date or all, then
  293. if (needs_defaults && (defaults == OptionDefaults::Date || defaults == OptionDefaults::All)) {
  294. // i. For each property name prop of « "year", "month", "day" », do
  295. auto set_property_value = [&](auto& value) {
  296. // 1. Set formatOptions.[[<prop>]] to "numeric".
  297. value = ::Locale::CalendarPatternStyle::Numeric;
  298. };
  299. set_property_value(format_options.year);
  300. set_property_value(format_options.month);
  301. set_property_value(format_options.day);
  302. }
  303. // e. If needDefaults is true and defaults is either time or all, then
  304. if (needs_defaults && (defaults == OptionDefaults::Time || defaults == OptionDefaults::All)) {
  305. // i. For each property name prop of « "hour", "minute", "second" », do
  306. auto set_property_value = [&](auto& value) {
  307. // 1. Set formatOptions.[[<prop>]] to "numeric".
  308. value = ::Locale::CalendarPatternStyle::Numeric;
  309. };
  310. set_property_value(format_options.hour);
  311. set_property_value(format_options.minute);
  312. set_property_value(format_options.second);
  313. }
  314. // f. Let formats be dataLocaleData.[[formats]].[[<resolvedCalendar>]].
  315. auto formats = TRY_OR_THROW_OOM(vm, ::Locale::get_calendar_available_formats(data_locale, date_time_format->calendar()));
  316. // g. If matcher is "basic", then
  317. if (matcher.as_string().utf8_string_view() == "basic"sv) {
  318. // i. Let bestFormat be BasicFormatMatcher(formatOptions, formats).
  319. best_format = basic_format_matcher(format_options, move(formats));
  320. }
  321. // h. Else,
  322. else {
  323. // i. Let bestFormat be BestFitFormatMatcher(formatOptions, formats).
  324. best_format = best_fit_format_matcher(format_options, move(formats));
  325. }
  326. }
  327. // 45. For each row in Table 6, except the header row, in table order, do
  328. date_time_format->for_each_calendar_field_zipped_with(*best_format, [&](auto& date_time_format_field, auto const& best_format_field, auto) {
  329. // a. Let prop be the name given in the Property column of the row.
  330. // b. If bestFormat has a field [[<prop>]], then
  331. if (best_format_field.has_value()) {
  332. // i. Let p be bestFormat.[[<prop>]].
  333. // ii. Set dateTimeFormat's internal slot whose name is the Internal Slot column of the row to p.
  334. date_time_format_field = best_format_field;
  335. }
  336. });
  337. String pattern;
  338. Vector<::Locale::CalendarRangePattern> range_patterns;
  339. // 46. If dateTimeFormat.[[Hour]] is undefined, then
  340. if (!date_time_format->has_hour()) {
  341. // a. Set dateTimeFormat.[[HourCycle]] to undefined.
  342. date_time_format->clear_hour_cycle();
  343. }
  344. // 47. If dateTimeFormat.[[HourCycle]] is "h11" or "h12", then
  345. if ((hour_cycle_value == ::Locale::HourCycle::H11) || (hour_cycle_value == ::Locale::HourCycle::H12)) {
  346. // a. Let pattern be bestFormat.[[pattern12]].
  347. if (best_format->pattern12.has_value()) {
  348. pattern = best_format->pattern12.release_value();
  349. } else {
  350. // Non-standard, LibUnicode only provides [[pattern12]] when [[pattern]] has a day
  351. // period. Other implementations provide [[pattern12]] as a copy of [[pattern]].
  352. pattern = move(best_format->pattern);
  353. }
  354. // b. Let rangePatterns be bestFormat.[[rangePatterns12]].
  355. range_patterns = TRY_OR_THROW_OOM(vm, ::Locale::get_calendar_range12_formats(data_locale, date_time_format->calendar(), best_format->skeleton));
  356. }
  357. // 48. Else,
  358. else {
  359. // a. Let pattern be bestFormat.[[pattern]].
  360. pattern = move(best_format->pattern);
  361. // b. Let rangePatterns be bestFormat.[[rangePatterns]].
  362. range_patterns = TRY_OR_THROW_OOM(vm, ::Locale::get_calendar_range_formats(data_locale, date_time_format->calendar(), best_format->skeleton));
  363. }
  364. // 49. Set dateTimeFormat.[[Pattern]] to pattern.
  365. date_time_format->set_pattern(move(pattern));
  366. // 50. Set dateTimeFormat.[[RangePatterns]] to rangePatterns.
  367. date_time_format->set_range_patterns(move(range_patterns));
  368. // 51. Return dateTimeFormat.
  369. return date_time_format;
  370. }
  371. }