Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit287e319

Browse files
authored
fix: use navigator.locale to evaluate time format (#17025)
Fixes:#15452
1 parent3bd32a2 commit287e319

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

‎site/src/pages/UserSettingsPage/SchedulePage/ScheduleForm.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const ScheduleForm: FC<ScheduleFormProps> = ({
7979
},
8080
});
8181
constgetFieldHelpers=getFormHelpers<ScheduleFormValues>(form,submitError);
82+
constbrowserLocale=navigator.language||"en-US";
8283

8384
return(
8485
<FormonSubmit={form.handleSubmit}>
@@ -127,7 +128,12 @@ export const ScheduleForm: FC<ScheduleFormProps> = ({
127128
disabled
128129
fullWidth
129130
label="Next occurrence"
130-
value={quietHoursDisplay(form.values.time,form.values.timezone,now)}
131+
value={quietHoursDisplay(
132+
browserLocale,
133+
form.values.time,
134+
form.values.timezone,
135+
now,
136+
)}
131137
/>
132138

133139
<div>

‎site/src/utils/schedule.test.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ describe("util/schedule", () => {
7878
});
7979

8080
describe("quietHoursDisplay",()=>{
81-
it("midnight",()=>{
81+
it("midnight in Poland",()=>{
8282
constquietHoursStart=quietHoursDisplay(
83+
"pl",
8384
"00:00",
8485
"Australia/Sydney",
8586
newDate("2023-09-06T15:00:00.000+10:00"),
@@ -89,8 +90,9 @@ describe("util/schedule", () => {
8990
"00:00 tomorrow (in 9 hours) in Australia/Sydney",
9091
);
9192
});
92-
it("five o'clock today",()=>{
93+
it("five o'clock today in Sweden",()=>{
9394
constquietHoursStart=quietHoursDisplay(
95+
"sv",
9496
"17:00",
9597
"Europe/London",
9698
newDate("2023-09-06T15:00:00.000+10:00"),
@@ -100,15 +102,28 @@ describe("util/schedule", () => {
100102
"17:00 today (in 11 hours) in Europe/London",
101103
);
102104
});
103-
it("lunch tomorrow",()=>{
105+
it("five o'clock today in Finland",()=>{
104106
constquietHoursStart=quietHoursDisplay(
107+
"fl",
108+
"17:00",
109+
"Europe/London",
110+
newDate("2023-09-06T15:00:00.000+10:00"),
111+
);
112+
113+
expect(quietHoursStart).toBe(
114+
"5:00 PM today (in 11 hours) in Europe/London",
115+
);
116+
});
117+
it("lunch tomorrow in England",()=>{
118+
constquietHoursStart=quietHoursDisplay(
119+
"en",
105120
"13:00",
106121
"US/Central",
107122
newDate("2023-09-06T08:00:00.000+10:00"),
108123
);
109124

110125
expect(quietHoursStart).toBe(
111-
"13:00 tomorrow (in 20 hours) in US/Central",
126+
"1:00 PM tomorrow (in 20 hours) in US/Central",
112127
);
113128
});
114129
});

‎site/src/utils/schedule.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export const timeToCron = (time: string, tz?: string) => {
256256
};
257257

258258
exportconstquietHoursDisplay=(
259+
browserLocale:string,
259260
time:string,
260261
tz:string,
261262
now:Date|undefined,
@@ -276,7 +277,14 @@ export const quietHoursDisplay = (
276277

277278
consttoday=dayjs(now).tz(tz);
278279
constday=dayjs(parsed.next().toDate()).tz(tz);
279-
letdisplay=day.format("HH:mm");
280+
281+
constformattedTime=newIntl.DateTimeFormat(browserLocale,{
282+
hour:"numeric",
283+
minute:"numeric",
284+
timeZone:tz,
285+
}).format(day.toDate());
286+
287+
letdisplay=formattedTime;
280288

281289
if(day.isSame(today,"day")){
282290
display+=" today";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp