summaryrefslogtreecommitdiffstats
path: root/js/src/builtin/intl/IntlObject.js
blob: c62b38282fb001d3f71d564ad6337c3171918d68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
 * 8.2.1 Intl.getCanonicalLocales ( locales )
 *
 * ES2017 Intl draft rev 947aa9a0c853422824a0c9510d8f09be3eb416b9
 */
function Intl_getCanonicalLocales(locales) {
  // Steps 1-2.
  return CanonicalizeLocaleList(locales);
}

/**
 * Intl.supportedValuesOf ( key )
 */
function Intl_supportedValuesOf(key) {
  // Step 1.
  key = ToString(key);

  // Steps 2-9.
  return intl_SupportedValuesOf(key);
}

/**
 * This function is a custom function in the style of the standard Intl.*
 * functions, that isn't part of any spec or proposal yet.
 *
 * Returns an object with the following properties:
 *   locale:
 *     The actual resolved locale.
 *
 *   calendar:
 *     The default calendar of the resolved locale.
 *
 *   firstDayOfWeek:
 *     The first day of the week for the resolved locale.
 *
 *   minDays:
 *     The minimum number of days in a week for the resolved locale.
 *
 *   weekend:
 *     The days of the week considered as the weekend for the resolved locale.
 *
 * Days are encoded as integers in the range 1=Monday to 7=Sunday.
 */
function Intl_getCalendarInfo(locales) {
  // 1. Let requestLocales be ? CanonicalizeLocaleList(locales).
  var requestedLocales = CanonicalizeLocaleList(locales);

  var DateTimeFormat = dateTimeFormatInternalProperties;

  // 2. Let localeData be %DateTimeFormat%.[[localeData]].
  var localeData = DateTimeFormat.localeData;

  // 3. Let localeOpt be a new Record.
  var localeOpt = new_Record();

  // 4. Set localeOpt.[[localeMatcher]] to "best fit".
  localeOpt.localeMatcher = "best fit";

  // 5. Let r be ResolveLocale(%DateTimeFormat%.[[availableLocales]],
  //    requestedLocales, localeOpt,
  //    %DateTimeFormat%.[[relevantExtensionKeys]], localeData).
  var r = ResolveLocale(
    "DateTimeFormat",
    requestedLocales,
    localeOpt,
    DateTimeFormat.relevantExtensionKeys,
    localeData
  );

  // 6. Let result be GetCalendarInfo(r.[[locale]]).
  var result = intl_GetCalendarInfo(r.locale);
  DefineDataProperty(result, "calendar", r.ca);
  DefineDataProperty(result, "locale", r.locale);

  // 7. Return result.
  return result;
}