From c8f73bef1efe44439f6275ba23b2035f1bc7f78d Mon Sep 17 00:00:00 2001 From: Slincnik Date: Mon, 9 Dec 2024 13:41:36 +0300 Subject: [PATCH] refactor: delete useless depend moment --- package.json | 1 - pnpm-lock.yaml | 8 -------- src/commands/IAT/checkjar.js | 5 ++--- src/helpers/functions.js | 24 ++++-------------------- 4 files changed, 6 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 1b98402d..f00df321 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "i18next": "^24.0.0", "i18next-fs-backend": "^2.6.0", "md5": "^2.3.0", - "moment": "^2.29.4", "mongoose": "^8.8.2", "ms": "^2.1.3", "node-fetch": "^2.7.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c6b4d075..4740b050 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -56,9 +56,6 @@ importers: md5: specifier: ^2.3.0 version: 2.3.0 - moment: - specifier: ^2.29.4 - version: 2.30.1 mongoose: specifier: ^8.8.2 version: 8.8.2(socks@2.8.3) @@ -1099,9 +1096,6 @@ packages: engines: {node: '>=10'} hasBin: true - moment@2.30.1: - resolution: {integrity: sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==} - mongodb-connection-string-url@3.0.1: resolution: {integrity: sha512-XqMGwRX0Lgn05TDB4PyG2h2kKO/FfWJyCzYQbIhXUxz7ETt0I/FqHjUeqj37irJ+Dl1ZtU82uYyj14u2XsZKfg==} @@ -2748,8 +2742,6 @@ snapshots: mkdirp@1.0.4: {} - moment@2.30.1: {} - mongodb-connection-string-url@3.0.1: dependencies: '@types/whatwg-url': 11.0.5 diff --git a/src/commands/IAT/checkjar.js b/src/commands/IAT/checkjar.js index 8618c3f4..2aeb8965 100644 --- a/src/commands/IAT/checkjar.js +++ b/src/commands/IAT/checkjar.js @@ -1,7 +1,6 @@ const { SlashCommandBuilder, InteractionContextType, ApplicationIntegrationType } = require("discord.js"); const BaseCommand = require("../../base/BaseCommand"), - fetch = require("node-fetch"), - moment = require("moment"); + fetch = require("node-fetch"); class Checkjar extends BaseCommand { /** @@ -56,7 +55,7 @@ class Checkjar extends BaseCommand { jarTransactions.length = 10; jarTransactions.forEach(t => { - const time = moment.unix(t.time); + const time = new Intl.DateTimeFormat("ru-RU").format(t.time); embed.data.fields.push([ { diff --git a/src/helpers/functions.js b/src/helpers/functions.js index 38cbb15b..578d6f55 100644 --- a/src/helpers/functions.js +++ b/src/helpers/functions.js @@ -1,5 +1,3 @@ -import moment from "moment"; - /** * Asynchronously iterates over a collection and executes a callback function for each item. * @@ -69,6 +67,7 @@ export function randomNum(min = 0, max = 100) { return Math.floor(Math.random() * (max - min + 1) + min); } + /** * Formats a date for the specified client and locale. * @@ -79,24 +78,9 @@ export function randomNum(min = 0, max = 100) { * @returns {string} The formatted date. */ export function printDate(client, date, format = null, locale = client.defaultLanguage.name) { - const languageData = client.languages.find(language => language.name === locale); - if (format === "" || format === null) format = languageData.defaultMomentFormat; - return moment(new Date(date)).locale(languageData.moment).format(format); -} -/** - * Formats a time value relative to the current time. - * - * @param {Object} client - The client object containing language data. - * @param {string|number|Date} time - The time value to format. - * @param {boolean} [type=false] - If true, formats the time as "X time ago", otherwise formats it as "in X time". - * @param {boolean} [prefix=true] - If true, includes a prefix like "in" or "ago" in the formatted time. - * @param {string} [locale=client.defaultLanguage.name] - The locale to use for formatting the time. - * @returns {string} The formatted time value. - */ -export function convertTime(client, time, type = false, prefix = true, locale = client.defaultLanguage.name) { - const languageData = client.languages.find(language => language.name === locale); - const m = moment(time).locale(languageData.moment); - return type ? m.toNow(!prefix) : m.fromNow(!prefix); + const { format: languageFormat, locale: localeFormat } = client.languages.find(language => language.name === locale); + if (format === "" || format === null) format = languageFormat; + return new Intl.DateTimeFormat(localeFormat).format(date); } /**