mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
timerender: Replace date-fns format with Intl.DateTimeFormat.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
581092a964
commit
64a7810065
@@ -2,7 +2,6 @@ import {
|
|||||||
differenceInCalendarDays,
|
differenceInCalendarDays,
|
||||||
differenceInHours,
|
differenceInHours,
|
||||||
differenceInMinutes,
|
differenceInMinutes,
|
||||||
format,
|
|
||||||
formatISO,
|
formatISO,
|
||||||
isEqual,
|
isEqual,
|
||||||
isValid,
|
isValid,
|
||||||
@@ -111,7 +110,6 @@ export function get_localized_date_or_time_for_format(
|
|||||||
|
|
||||||
// Exported for tests only.
|
// Exported for tests only.
|
||||||
export function get_tz_with_UTC_offset(time: number | Date): string {
|
export function get_tz_with_UTC_offset(time: number | Date): string {
|
||||||
const tz_offset = format(time, "xxx");
|
|
||||||
let timezone = new Intl.DateTimeFormat(user_settings.default_language, {timeZoneName: "short"})
|
let timezone = new Intl.DateTimeFormat(user_settings.default_language, {timeZoneName: "short"})
|
||||||
.formatToParts(time)
|
.formatToParts(time)
|
||||||
.find(({type}) => type === "timeZoneName")?.value;
|
.find(({type}) => type === "timeZoneName")?.value;
|
||||||
@@ -125,7 +123,12 @@ export function get_tz_with_UTC_offset(time: number | Date): string {
|
|||||||
// show that along with (UTC+x:y)
|
// show that along with (UTC+x:y)
|
||||||
timezone = /GMT[+-][\d:]*/.test(timezone ?? "") ? "" : timezone;
|
timezone = /GMT[+-][\d:]*/.test(timezone ?? "") ? "" : timezone;
|
||||||
|
|
||||||
const tz_UTC_offset = `(UTC${tz_offset})`;
|
const tz_offset = new Intl.DateTimeFormat(user_settings.default_language, {
|
||||||
|
timeZoneName: "longOffset",
|
||||||
|
})
|
||||||
|
.formatToParts(time)
|
||||||
|
.find(({type}) => type === "timeZoneName")!.value;
|
||||||
|
const tz_UTC_offset = `(${tz_offset.replace(/^GMT/, "UTC")})`;
|
||||||
|
|
||||||
if (timezone) {
|
if (timezone) {
|
||||||
return timezone + " " + tz_UTC_offset;
|
return timezone + " " + tz_UTC_offset;
|
||||||
|
|||||||
Reference in New Issue
Block a user