fixed desktop version

This commit is contained in:
SlimusMinus
2026-10-23 00:02:44 +03:00
parent 83ae74636b
commit 140a31982a
19 changed files with 2446 additions and 132 deletions

27
src/utils/relativeTime.js Normal file
View File

@@ -0,0 +1,27 @@
const UNITS = [
["year", 365 * 24 * 3600],
["month", 30 * 24 * 3600],
["week", 7 * 24 * 3600],
["day", 24 * 3600],
["hour", 3600],
["minute", 60],
];
/**
* «5 минут назад», «вчера», «2 недели назад» — по языку интерфейса.
* Возвращает null для пустой/некорректной даты.
*/
export function formatRelativeTime(value, language = "ru", now = Date.now()) {
if (!value) return null;
const time = new Date(value).getTime();
if (!Number.isFinite(time)) return null;
const diffSec = Math.round((time - now) / 1000);
const abs = Math.abs(diffSec);
const rtf = new Intl.RelativeTimeFormat(language, { numeric: "auto" });
for (const [unit, sec] of UNITS) {
if (abs >= sec) return rtf.format(Math.round(diffSec / sec), unit);
}
return rtf.format(0, "minute");
}