Skip to content

Commit 1a6675d

Browse files
Frontend/i18n: Default localizeDateTime to the browser's timezone. (#8124)
1 parent 00a7bd0 commit 1a6675d

8 files changed

Lines changed: 11 additions & 15 deletions

File tree

app/web/features/auth/InviteCodesPage.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ListInviteCodesRes } from "proto/account_pb";
1919
import React from "react";
2020
import { inviteRoute } from "routes";
2121
import { service } from "service";
22-
import { BROWSER_TIMEZONE, localizeDateTime } from "utils/date";
22+
import { localizeDateTime } from "utils/date";
2323

2424
import { inviteCodesKey } from "../queryKeys";
2525

@@ -166,7 +166,6 @@ export default function InviteCodesPage() {
166166
datetime: localizeDateTime(
167167
new Date(c.created.seconds * 1000),
168168
{
169-
timezone: BROWSER_TIMEZONE,
170169
locale: locale,
171170
abbreviate: true,
172171
},
@@ -181,7 +180,6 @@ export default function InviteCodesPage() {
181180
datetime: localizeDateTime(
182181
new Date(c.disabled.seconds * 1000),
183182
{
184-
timezone: BROWSER_TIMEZONE,
185183
locale,
186184
abbreviate: true,
187185
},

app/web/features/auth/jail/ModNoteCard.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ModNote } from "proto/account_pb";
77
import { useState } from "react";
88
import { service } from "service";
99
import { theme } from "theme";
10-
import { BROWSER_TIMEZONE, localizeDateTime, timestamp2Date } from "utils/date";
10+
import { localizeDateTime, timestamp2Date } from "utils/date";
1111

1212
const StyledNoteContainer = styled("div")(() => ({
1313
marginBottom: theme.spacing(4),
@@ -34,7 +34,6 @@ export default function ModNoteCard({ note, updateJailed }: ModNoteCardProps) {
3434
const [loading, setLoading] = useState(false);
3535

3636
const formattedTime = localizeDateTime(timestamp2Date(note.created!), {
37-
timezone: BROWSER_TIMEZONE,
3837
locale,
3938
abbreviate: true,
4039
});

app/web/features/auth/logins/LoginCard.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { AUTH, GLOBAL } from "i18n/namespaces";
2121
import { useTranslation } from "next-i18next";
2222
import { ActiveSession } from "proto/account_pb";
2323
import { service } from "service";
24-
import { BROWSER_TIMEZONE, localizeDateTime, timestamp2Date } from "utils/date";
24+
import { localizeDateTime, timestamp2Date } from "utils/date";
2525
import { timeAgo } from "utils/timeAgo";
2626

2727
const StyledCard = styled(Card)(({ theme }) => ({
@@ -45,13 +45,11 @@ export default function LoginsPage({
4545
locale,
4646
});
4747
const createdDisplay = localizeDateTime(timestamp2Date(session.created!), {
48-
timezone: BROWSER_TIMEZONE,
4948
locale,
5049
includeSeconds: true,
5150
abbreviate: true,
5251
});
5352
const expiryDisplay = localizeDateTime(timestamp2Date(session.expiry!), {
54-
timezone: BROWSER_TIMEZONE,
5553
locale,
5654
includeTime: false,
5755
abbreviate: true,

app/web/features/communities/discussions/DiscussionPage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { useRouter } from "next/router";
1717
import { Discussion } from "proto/discussions_pb";
1818
import { service } from "service";
1919
import { theme } from "theme";
20-
import { BROWSER_TIMEZONE, localizeDateTime, timestamp2Date } from "utils/date";
20+
import { localizeDateTime, timestamp2Date } from "utils/date";
2121

2222
import CommunityBase from "../CommunityBase";
2323
import CommunityPageSubHeader from "../CommunityPage/CommunityPageSubHeader";
@@ -143,7 +143,6 @@ export default function DiscussionPage({
143143
dateOnly: localizeDateTime(
144144
timestamp2Date(discussion.created!),
145145
{
146-
timezone: BROWSER_TIMEZONE,
147146
locale,
148147
includeTime: false,
149148
},

app/web/features/communities/events/EventCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export default function EventCard({
141141
dayjs(timestamp2Date(event.startTime!)),
142142
dayjs(timestamp2Date(event.endTime!)),
143143
{
144+
// TODO(#8064): Should use the event.timezone, but it's currently incorrect.
144145
timezone: BROWSER_TIMEZONE,
145146
locale,
146147
includeDayOfWeek: true,

app/web/features/communities/events/EventPage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ export default function EventPage({
417417
dayjs(timestamp2Date(event.startTime!)),
418418
dayjs(timestamp2Date(event.endTime!)),
419419
{
420+
// TODO(#8064): Should use the event.timezone, but it's currently incorrect.
420421
timezone: BROWSER_TIMEZONE,
421422
locale,
422423
includeDayOfWeek: true,

app/web/features/communities/events/LongEventCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const LongEventCard = ({
139139
dayjs(timestamp2Date(event.startTime!)),
140140
dayjs(timestamp2Date(event.endTime!)),
141141
{
142+
// TODO(#8064): Should use the event.timezone, but it's currently incorrect.
142143
timezone: BROWSER_TIMEZONE,
143144
locale,
144145
includeDayOfWeek: true,

app/web/utils/date.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ const numNights = (date1: string, date2: string) => {
1616
return diffDays;
1717
};
1818

19-
/// Explicitly identifies the browser's timezone (clearer than "undefined").
19+
/// Allow call sites to explicitly reference the browser's timezone (clearer than "undefined").
2020
export const BROWSER_TIMEZONE: unique symbol = Symbol("browser-timezone");
2121
export const UTC_TIMEZONE: string = "Etc/UTC";
2222

2323
interface LocalizeDateTimeParams {
24-
/// The timezone to be used to figure the date components.
25-
/// This is a required parameter to avoid unexpected results.
26-
timezone: string | typeof BROWSER_TIMEZONE;
2724
/// The locale to localize in.
2825
locale: string;
26+
/// The timezone to be used to figure the date components (defaults to the browser's).
27+
timezone?: string | typeof BROWSER_TIMEZONE;
2928
/// Whether to include the date (defaults to true).
3029
includeDate?: boolean;
3130
/// If including the date, whether to include the day of week (defaults to false).
@@ -106,7 +105,7 @@ function createIntlDateTimeFormat(
106105
options.second = "numeric";
107106
}
108107
}
109-
if (args.timezone !== BROWSER_TIMEZONE) {
108+
if (args.timezone && args.timezone !== BROWSER_TIMEZONE) {
110109
options.timeZone = args.timezone;
111110
}
112111
return Intl.DateTimeFormat(args.locale, options);

0 commit comments

Comments
 (0)