From db97eda391aba86f4dfd7376a7d1eff9e82c0a9c Mon Sep 17 00:00:00 2001 From: "Danil S." <135337715+sh1shd@users.noreply.github.com> Date: Mon, 10 Nov 2025 14:04:50 +0000 Subject: [PATCH 1/4] chore: use `Intl` for date formatting --- web/assets/js/util/date-util.js | 151 ------------------ web/assets/js/util/index.js | 31 ++++ web/html/common/page.html | 1 - web/html/component/aClientTable.html | 70 ++------ web/html/form/inbound.html | 4 +- web/html/inbounds.html | 28 +--- web/html/index.html | 4 +- web/html/modals/inbound_info_modal.html | 21 +-- .../settings/panel/subscription/subpage.html | 24 +-- 9 files changed, 57 insertions(+), 277 deletions(-) delete mode 100644 web/assets/js/util/date-util.js diff --git a/web/assets/js/util/date-util.js b/web/assets/js/util/date-util.js deleted file mode 100644 index bbca1272..00000000 --- a/web/assets/js/util/date-util.js +++ /dev/null @@ -1,151 +0,0 @@ -const oneMinute = 1000 * 60; // MilliseConds in a Minute -const oneHour = oneMinute * 60; // The milliseconds of one hour -const oneDay = oneHour * 24; // The Number of MilliseConds A Day -const oneWeek = oneDay * 7; // The milliseconds per week -const oneMonth = oneDay * 30; // The milliseconds of a month - -/** - * Decrease according to the number of days - * - * @param days to reduce the number of days to be reduced - */ -Date.prototype.minusDays = function (days) { - return this.minusMillis(oneDay * days); -}; - -/** - * Increase according to the number of days - * - * @param days The number of days to be increased - */ -Date.prototype.plusDays = function (days) { - return this.plusMillis(oneDay * days); -}; - -/** - * A few - * - * @param hours to be reduced - */ -Date.prototype.minusHours = function (hours) { - return this.minusMillis(oneHour * hours); -}; - -/** - * Increase hourly - * - * @param hours to increase the number of hours - */ -Date.prototype.plusHours = function (hours) { - return this.plusMillis(oneHour * hours); -}; - -/** - * Make reduction in minutes - * - * @param minutes to reduce the number of minutes - */ -Date.prototype.minusMinutes = function (minutes) { - return this.minusMillis(oneMinute * minutes); -}; - -/** - * Add in minutes - * - * @param minutes to increase the number of minutes - */ -Date.prototype.plusMinutes = function (minutes) { - return this.plusMillis(oneMinute * minutes); -}; - -/** - * Decrease in milliseconds - * - * @param millis to reduce the milliseconds - */ -Date.prototype.minusMillis = function(millis) { - let time = this.getTime() - millis; - let newDate = new Date(); - newDate.setTime(time); - return newDate; -}; - -/** - * Add in milliseconds to increase - * - * @param millis to increase the milliseconds to increase - */ -Date.prototype.plusMillis = function(millis) { - let time = this.getTime() + millis; - let newDate = new Date(); - newDate.setTime(time); - return newDate; -}; - -/** - * Setting time is 00: 00: 00.000 on the day - */ -Date.prototype.setMinTime = function () { - this.setHours(0); - this.setMinutes(0); - this.setSeconds(0); - this.setMilliseconds(0); - return this; -}; - -/** - * Setting time is 23: 59: 59.999 on the same day - */ -Date.prototype.setMaxTime = function () { - this.setHours(23); - this.setMinutes(59); - this.setSeconds(59); - this.setMilliseconds(999); - return this; -}; - -/** - * Formatting date - */ -Date.prototype.formatDate = function () { - return this.getFullYear() + "-" + NumberFormatter.addZero(this.getMonth() + 1) + "-" + NumberFormatter.addZero(this.getDate()); -}; - -/** - * Format time - */ -Date.prototype.formatTime = function () { - return NumberFormatter.addZero(this.getHours()) + ":" + NumberFormatter.addZero(this.getMinutes()) + ":" + NumberFormatter.addZero(this.getSeconds()); -}; - -/** - * Formatting date plus time - * - * @param split Date and time separation symbols, default is a space - */ -Date.prototype.formatDateTime = function (split = ' ') { - return this.formatDate() + split + this.formatTime(); -}; - -class DateUtil { - // String to date object - static parseDate(str) { - return new Date(str.replace(/-/g, '/')); - } - - static formatMillis(millis) { - return moment(millis).format('YYYY-M-D HH:mm:ss'); - } - - static firstDayOfMonth() { - const date = new Date(); - date.setDate(1); - date.setMinTime(); - return date; - } - - static convertToJalalian(date) { - return date && moment.isMoment(date) ? date.format('jYYYY/jMM/jDD HH:mm:ss') : null; - } - -} diff --git a/web/assets/js/util/index.js b/web/assets/js/util/index.js index 902974f0..13bf68b1 100644 --- a/web/assets/js/util/index.js +++ b/web/assets/js/util/index.js @@ -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'); + } } \ No newline at end of file diff --git a/web/html/common/page.html b/web/html/common/page.html index f1c58fe1..c0a7ca63 100644 --- a/web/html/common/page.html +++ b/web/html/common/page.html @@ -44,7 +44,6 @@ - - {{ template "page/head_end" .}}