in lib/Platform/Intl/java/com/facebook/hermes/intl/DateTimeFormat.java [170:401]
private void initializeDateTimeFormat(List<String> locales, Map<String, Object> inOptions)
throws JSRangeErrorException {
List<String> relevantExtensionKeys = Arrays.asList("ca", "nu", "hc");
// 2
Object options = ToDateTimeOptions(inOptions, "any", "date");
// 3
Object opt = JSObjects.newObject();
// 4,5,
Object matcher =
OptionHelpers.GetOption(
options,
Constants.LOCALEMATCHER,
OptionHelpers.OptionType.STRING,
Constants.LOCALEMATCHER_POSSIBLE_VALUES,
Constants.LOCALEMATCHER_BESTFIT);
JSObjects.Put(opt, "localeMatcher", matcher);
// 6 - 8
Object calendar =
OptionHelpers.GetOption(
options,
"calendar",
OptionHelpers.OptionType.STRING,
JSObjects.Undefined(),
JSObjects.Undefined());
if (!JSObjects.isUndefined(calendar)) {
if (!isLocaleIdType(JSObjects.getJavaString(calendar)))
throw new JSRangeErrorException("Invalid calendar option !");
}
JSObjects.Put(opt, "ca", calendar);
// 9 - 11
Object numberingSystem =
OptionHelpers.GetOption(
options,
"numberingSystem",
OptionHelpers.OptionType.STRING,
JSObjects.Undefined(),
JSObjects.Undefined());
if (!JSObjects.isUndefined(numberingSystem)) {
if (!isLocaleIdType(JSObjects.getJavaString(numberingSystem)))
throw new JSRangeErrorException("Invalid numbering system !");
}
JSObjects.Put(opt, "nu", numberingSystem);
// 12 - 15
Object hour12 =
OptionHelpers.GetOption(
options,
"hour12",
OptionHelpers.OptionType.BOOLEAN,
JSObjects.Undefined(),
JSObjects.Undefined());
Object hourCycle =
OptionHelpers.GetOption(
options,
"hourCycle",
OptionHelpers.OptionType.STRING,
new String[] {"h11", "h12", "h23", "h24"},
JSObjects.Undefined());
if (!JSObjects.isUndefined(hour12)) hourCycle = JSObjects.Null();
JSObjects.Put(opt, "hc", hourCycle);
// 16 - 23
HashMap<String, Object> r = LocaleResolver.resolveLocale(locales, opt, relevantExtensionKeys);
mResolvedLocaleObject = (ILocaleObject<?>) JSObjects.getJavaMap(r).get("locale");
mResolvedLocaleObjectForResolvedOptions = mResolvedLocaleObject.cloneObject();
Object calendarResolved = JSObjects.Get(r, "ca");
if (!JSObjects.isNull(calendarResolved)) {
useDefaultCalendar = false;
mCalendar = JSObjects.getJavaString(calendarResolved);
} else {
useDefaultCalendar = true;
mCalendar = mPlatformDateTimeFormatter.getDefaultCalendarName(mResolvedLocaleObject);
}
Object numeringSystemResolved = JSObjects.Get(r, "nu");
if (!JSObjects.isNull(numeringSystemResolved)) {
useDefaultNumberSystem = false;
mNumberingSystem = JSObjects.getJavaString(numeringSystemResolved);
} else {
useDefaultNumberSystem = true;
mNumberingSystem =
mPlatformDateTimeFormatter.getDefaultNumberingSystem(mResolvedLocaleObject);
}
Object hourCycleResolved = JSObjects.Get(r, "hc");
// 24 - 27
Object timeZone = JSObjects.Get(options, "timeZone");
if (JSObjects.isUndefined(timeZone)) {
timeZone = DefaultTimeZone();
} else {
timeZone = normalizeTimeZone(timeZone.toString());
}
mTimeZone = timeZone;
// 28 - 34
Object formatMatcher =
OptionHelpers.GetOption(
options,
"formatMatcher",
OptionHelpers.OptionType.STRING,
new String[] {"basic", "best fit"},
"best fit");
mFormatMatcher =
OptionHelpers.searchEnum(
IPlatformDateTimeFormatter.FormatMatcher.class, JSObjects.getJavaString(formatMatcher));
// 29, 35
Object weekDay =
OptionHelpers.GetOption(
options,
"weekday",
OptionHelpers.OptionType.STRING,
new String[] {"long", "short", "narrow"},
JSObjects.Undefined());
mWeekDay = OptionHelpers.searchEnum(IPlatformDateTimeFormatter.WeekDay.class, weekDay);
Object era =
OptionHelpers.GetOption(
options,
"era",
OptionHelpers.OptionType.STRING,
new String[] {"long", "short", "narrow"},
JSObjects.Undefined());
mEra = OptionHelpers.searchEnum(IPlatformDateTimeFormatter.Era.class, era);
Object year =
OptionHelpers.GetOption(
options,
"year",
OptionHelpers.OptionType.STRING,
new String[] {"numeric", "2-digit"},
JSObjects.Undefined());
mYear = OptionHelpers.searchEnum(IPlatformDateTimeFormatter.Year.class, year);
Object month =
OptionHelpers.GetOption(
options,
"month",
OptionHelpers.OptionType.STRING,
new String[] {"numeric", "2-digit", "long", "short", "narrow"},
JSObjects.Undefined());
mMonth = OptionHelpers.searchEnum(IPlatformDateTimeFormatter.Month.class, month);
Object day =
OptionHelpers.GetOption(
options,
"day",
OptionHelpers.OptionType.STRING,
new String[] {"numeric", "2-digit"},
JSObjects.Undefined());
mDay = OptionHelpers.searchEnum(IPlatformDateTimeFormatter.Day.class, day);
Object hour =
OptionHelpers.GetOption(
options,
"hour",
OptionHelpers.OptionType.STRING,
new String[] {"numeric", "2-digit"},
JSObjects.Undefined());
mHour = OptionHelpers.searchEnum(IPlatformDateTimeFormatter.Hour.class, hour);
Object minute =
OptionHelpers.GetOption(
options,
"minute",
OptionHelpers.OptionType.STRING,
new String[] {"numeric", "2-digit"},
JSObjects.Undefined());
mMinute = OptionHelpers.searchEnum(IPlatformDateTimeFormatter.Minute.class, minute);
Object second =
OptionHelpers.GetOption(
options,
"second",
OptionHelpers.OptionType.STRING,
new String[] {"numeric", "2-digit"},
JSObjects.Undefined());
mSecond = OptionHelpers.searchEnum(IPlatformDateTimeFormatter.Second.class, second);
Object timeZoneName =
OptionHelpers.GetOption(
options,
"timeZoneName",
OptionHelpers.OptionType.STRING,
new String[] {"long", "short"},
JSObjects.Undefined());
mTimeZoneName =
OptionHelpers.searchEnum(IPlatformDateTimeFormatter.TimeZoneName.class, timeZoneName);
// 36
if (JSObjects.isUndefined(hour)) {
mHourCycle = IPlatformDateTimeFormatter.HourCycle.UNDEFINED;
} else {
IPlatformDateTimeFormatter.HourCycle hcDefault =
mPlatformDateTimeFormatter.getDefaultHourCycle(mResolvedLocaleObject);
IPlatformDateTimeFormatter.HourCycle hc;
if (JSObjects.isNull(hourCycleResolved)) {
hc = hcDefault;
} else {
hc =
OptionHelpers.searchEnum(IPlatformDateTimeFormatter.HourCycle.class, hourCycleResolved);
}
if (!JSObjects.isUndefined(hour12)) {
if (JSObjects.getJavaBoolean(hour12)) { // true
if (hcDefault == IPlatformDateTimeFormatter.HourCycle.H11
|| hcDefault == IPlatformDateTimeFormatter.HourCycle.H23)
hc = IPlatformDateTimeFormatter.HourCycle.H11;
else hc = IPlatformDateTimeFormatter.HourCycle.H12;
} else {
if (hcDefault == IPlatformDateTimeFormatter.HourCycle.H11
|| hcDefault == IPlatformDateTimeFormatter.HourCycle.H23)
hc = IPlatformDateTimeFormatter.HourCycle.H23;
else hc = IPlatformDateTimeFormatter.HourCycle.H24;
}
}
mHourCycle = hc;
}
}