mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-21 23:05:46 +00:00
feat(themes): Theme Store install counts, downloads & sort (#1036)
* feat(themes): install counts, downloads, popularity & sort in the Theme Store Each registry theme now carries an install count and a last-changed date. Store rows show them in a dedicated meta panel (author, popularity bar, total downloads, last changed), plus a sort dropdown (most popular / newest / name), zebra-striped rows, a numbered pager, and a note that the stats refresh daily. Adds a shared formatRelativeTime helper (formatLastSeen now delegates to it). * test(themes): cover sort modes, pager jump and relative-time formatting * fix(build): gate nvidia_quirk_active to Linux Its only caller is the Linux branch of theme_animation_risk, so on Windows and macOS the function was dead code and tripped clippy's -D warnings. * docs: CHANGELOG + credits for theme store download stats & sort (#1036)
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Render a relative time like "3 hours ago" / "in 2 weeks" in the given locale,
|
||||
* picking the largest sensible unit. Locale-aware via `Intl.RelativeTimeFormat`,
|
||||
* so no per-string i18n keys are needed.
|
||||
*/
|
||||
export function formatRelativeTime(iso: string | number | Date, locale: string): string {
|
||||
const diffSec = (new Date(iso).getTime() - Date.now()) / 1000;
|
||||
const abs = Math.abs(diffSec);
|
||||
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });
|
||||
if (abs < 60) return rtf.format(Math.round(diffSec), 'second');
|
||||
if (abs < 3600) return rtf.format(Math.round(diffSec / 60), 'minute');
|
||||
if (abs < 86400) return rtf.format(Math.round(diffSec / 3600), 'hour');
|
||||
if (abs < 604800) return rtf.format(Math.round(diffSec / 86400), 'day');
|
||||
if (abs < 2592000) return rtf.format(Math.round(diffSec / 604800), 'week');
|
||||
if (abs < 31536000) return rtf.format(Math.round(diffSec / 2592000), 'month');
|
||||
return rtf.format(Math.round(diffSec / 31536000), 'year');
|
||||
}
|
||||
Reference in New Issue
Block a user