Skip to content

Fix countdown localization issue #2004

Fix countdown localization issue

Fix countdown localization issue #2004

Triggered via pull request October 18, 2024 05:40
Status Failure
Total duration 1m 1s
Artifacts

CI.yaml

on: pull_request
Matrix: Python
Fit to window
Zoom out
Zoom in

Annotations

2 errors
qa.spec.ts > QA > js/octorelay.js build remains: ui/qa.spec.ts#L12
Error: Snapshot `QA > js/octorelay.js build remains 1` mismatched - Expected + Received @@ -5,11 +5,11 @@ var closeBtnId = "pop-closer"; var closeIconHTML = '<span class="fa fa-close fa-sm"></span>'; var closeBtnHTML = `<button id="${closeBtnId}" type="button" class="close">${closeIconHTML}</button>`; // helpers/countdown.ts - var formatDeadline = (time) => { + var formatDeadline = (time, locales = [LOCALE, void 0]) => { let unit = "second"; let timeLeft = (time - Date.now()) / 1e3; if (timeLeft >= 60) { timeLeft /= 60; unit = "minute"; @@ -17,18 +17,25 @@ if (timeLeft >= 60) { timeLeft /= 60; unit = "hour"; } const isLastMinute = unit === "minute" && timeLeft < 2; - const formattedTimeLeft = new Intl.NumberFormat(LOCALE, { + for (const locale of locales) { + try { + const formattedTimeLeft = new Intl.NumberFormat(locale, { - style: "unit", + style: "unit", - unitDisplay: "long", + unitDisplay: "long", - minimumFractionDigits: isLastMinute ? 1 : 0, + minimumFractionDigits: isLastMinute ? 1 : 0, - maximumFractionDigits: isLastMinute ? 1 : 0, + maximumFractionDigits: isLastMinute ? 1 : 0, - unit + unit - }).format(Math.max(0, timeLeft)); + }).format(Math.max(0, timeLeft)); - return `in ${formattedTimeLeft}`; + return `in ${formattedTimeLeft}`; + } catch (error) { + console.warn(`Failed to format time using ${locale} locale`, error); + } + } + return `in ${timeLeft} ${unit}${timeLeft > 1 ? "s" : ""}`; }; var getCountdownDelay = (deadline) => deadline - Date.now() > 12e4 ? 6e4 : 1e3; var setCountdown = (selector, deadline) => { const delay = getCountdownDelay(deadline); let disposer; ❯ qa.spec.ts:12:20
UI
Process completed with exit code 1.