chore: use Intl for date formatting (#3588)

* chore: use `Intl` for date formatting

* fix: show last traffic reset

* chore: use raw timestamps

* fix: remove unnecessary import
This commit is contained in:
Danil S.
2025-12-04 05:37:27 +07:00
committed by GitHub
parent e8c509c720
commit 70f6d6b21a
9 changed files with 57 additions and 278 deletions

View File

@@ -882,4 +882,35 @@ class FileManager {
link.remove();
}
}
class IntlUtil {
static formatDate(date) {
const language = LanguageManager.getLanguage()
let intlOptions = {
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric"
}
const intl = new Intl.DateTimeFormat(
language,
intlOptions
)
return intl.format(new Date(date))
}
static formatRelativeTime(date) {
const language = LanguageManager.getLanguage()
const now = new Date()
const diff = Math.round((date - now) / (1000 * 60 * 60 * 24))
const formatter = new Intl.RelativeTimeFormat(language, { numeric: 'auto' })
return formatter.format(diff, 'day');
}
}