Skip to content

Commit

Permalink
Draft: try with and without locale.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail committed Oct 18, 2024
1 parent a7f8c8d commit 0265b0e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions ui/helpers/countdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ export const formatDeadline = (time: number): string => {
unit = "hour";
}
const isLastMinute = unit === "minute" && timeLeft < 2;
const formattedTimeLeft = new Intl.NumberFormat(LOCALE, {
style: "unit",
unitDisplay: "long",
minimumFractionDigits: isLastMinute ? 1 : 0,
maximumFractionDigits: isLastMinute ? 1 : 0,
unit,
}).format(Math.max(0, timeLeft));
return `in ${formattedTimeLeft}`;
for (const locale of [LOCALE, undefined]) {
try {
const formattedTimeLeft = new Intl.NumberFormat(locale, {
style: "unit",
unitDisplay: "long",
minimumFractionDigits: isLastMinute ? 1 : 0,
maximumFractionDigits: isLastMinute ? 1 : 0,
unit,
}).format(Math.max(0, timeLeft));
return `in ${formattedTimeLeft}`;
} catch (error) {
console.warn(`Failed to format time using ${locale} locale`, error);
}
}
return `in ${time} seconds`;
};

export const getCountdownDelay = (deadline: number): number =>
Expand Down

0 comments on commit 0265b0e

Please sign in to comment.