mirror of https://github.com/zulip/zulip.git
timerender: Remove unnecessary get_user_locale function.
Subscripting an empty array does not throw an exception in JavaScript, "default" is not a valid locale, and the browser APIs already fall back on unrecognized locales anyway. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
c539b8ee46
commit
100f91e1c9
|
@ -94,17 +94,6 @@ function get_format_options_for_type(type: DateOrTimeFormat): Intl.DateTimeForma
|
|||
}
|
||||
}
|
||||
|
||||
function get_user_locale(): string {
|
||||
const user_default_language = user_settings.default_language;
|
||||
let locale = "";
|
||||
try {
|
||||
locale = Intl.DateTimeFormat.supportedLocalesOf(user_default_language)[0];
|
||||
} catch {
|
||||
locale = "default";
|
||||
}
|
||||
return locale;
|
||||
}
|
||||
|
||||
// Common function for all date/time rendering in the project. Handles
|
||||
// localization using the user's configured locale and the
|
||||
// twenty_four_hour_time setting.
|
||||
|
@ -114,8 +103,10 @@ export function get_localized_date_or_time_for_format(
|
|||
date: Date | number,
|
||||
format: DateOrTimeFormat,
|
||||
): string {
|
||||
const locale = get_user_locale();
|
||||
return new Intl.DateTimeFormat(locale, get_format_options_for_type(format)).format(date);
|
||||
return new Intl.DateTimeFormat(
|
||||
user_settings.default_language,
|
||||
get_format_options_for_type(format),
|
||||
).format(date);
|
||||
}
|
||||
|
||||
// Exported for tests only.
|
||||
|
@ -467,8 +458,7 @@ export function get_full_datetime_clarification(
|
|||
time: Date,
|
||||
time_format: TimeFormat = "time_sec",
|
||||
): string {
|
||||
const locale = get_user_locale();
|
||||
const date_string = time.toLocaleDateString(locale);
|
||||
const date_string = time.toLocaleDateString(user_settings.default_language);
|
||||
let time_string = get_localized_date_or_time_for_format(time, time_format);
|
||||
|
||||
const tz_offset_str = get_tz_with_UTC_offset(time);
|
||||
|
|
|
@ -39,7 +39,7 @@ run_test("get_localized_date_or_time_for_format returns default date with incorr
|
|||
const date = date_2019;
|
||||
const expectedDate = "Friday, April 12, 2019";
|
||||
|
||||
user_settings.default_language = "invalidLanguageCode";
|
||||
user_settings.default_language = "invalid";
|
||||
const actualDate = timerender.get_localized_date_or_time_for_format(
|
||||
date,
|
||||
"weekday_dayofyear_year",
|
||||
|
|
Loading…
Reference in New Issue