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

fix: use navigator.locale to evaluate time format#17025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mtojek merged 1 commit intomainfrom15452-12-24-2
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,6 +79,7 @@ export const ScheduleForm: FC<ScheduleFormProps> = ({
},
});
const getFieldHelpers = getFormHelpers<ScheduleFormValues>(form, submitError);
const browserLocale = navigator.language || "en-US";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Disappointed we have to uselanguage as an approximation 😔. I prefer to use English US for text and UI language but Finland is used for numbers, time and currency. Yet this is not available to the browser (AFAICT).


return (
<Form onSubmit={form.handleSubmit}>
Expand DownExpand Up@@ -127,7 +128,12 @@ export const ScheduleForm: FC<ScheduleFormProps> = ({
disabled
fullWidth
label="Next occurrence"
value={quietHoursDisplay(form.values.time, form.values.timezone, now)}
value={quietHoursDisplay(
browserLocale,
form.values.time,
form.values.timezone,
now,
)}
/>

<div>
Expand Down
23 changes: 19 additions & 4 deletionssite/src/utils/schedule.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,8 +78,9 @@ describe("util/schedule", () => {
});

describe("quietHoursDisplay", () => {
it("midnight", () => {
it("midnight in Poland", () => {
const quietHoursStart = quietHoursDisplay(
"pl",
"00:00",
"Australia/Sydney",
new Date("2023-09-06T15:00:00.000+10:00"),
Expand All@@ -89,8 +90,9 @@ describe("util/schedule", () => {
"00:00 tomorrow (in 9 hours) in Australia/Sydney",
);
});
it("five o'clock today", () => {
it("five o'clock today in Sweden", () => {
const quietHoursStart = quietHoursDisplay(
"sv",
"17:00",
"Europe/London",
new Date("2023-09-06T15:00:00.000+10:00"),
Expand All@@ -100,15 +102,28 @@ describe("util/schedule", () => {
"17:00 today (in 11 hours) in Europe/London",
);
});
it("lunch tomorrow", () => {
it("five o'clock today in Finland", () => {
const quietHoursStart = quietHoursDisplay(
"fl",
"17:00",
"Europe/London",
new Date("2023-09-06T15:00:00.000+10:00"),
);

expect(quietHoursStart).toBe(
"5:00 PM today (in 11 hours) in Europe/London",
);
});
it("lunch tomorrow in England", () => {
const quietHoursStart = quietHoursDisplay(
"en",
"13:00",
"US/Central",
new Date("2023-09-06T08:00:00.000+10:00"),
);

expect(quietHoursStart).toBe(
"13:00 tomorrow (in 20 hours) in US/Central",
"1:00 PM tomorrow (in 20 hours) in US/Central",
);
});
});
Expand Down
10 changes: 9 additions & 1 deletionsite/src/utils/schedule.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -256,6 +256,7 @@ export const timeToCron = (time: string, tz?: string) => {
};

export const quietHoursDisplay = (
browserLocale: string,
time: string,
tz: string,
now: Date | undefined,
Expand All@@ -276,7 +277,14 @@ export const quietHoursDisplay = (

const today = dayjs(now).tz(tz);
const day = dayjs(parsed.next().toDate()).tz(tz);
let display = day.format("HH:mm");

const formattedTime = new Intl.DateTimeFormat(browserLocale, {
hour: "numeric",
minute: "numeric",
timeZone: tz,
}).format(day.toDate());

let display = formattedTime;

if (day.isSame(today, "day")) {
display += " today";
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp