From f07d4d67569fb6afd639e3f9ae8a62400f576cab Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 24 Sep 2024 19:32:23 +0200 Subject: [PATCH] find timezone based on locale --- package-lock.json | 22 ++++++++++++++++++++++ package.json | 1 + src/utils/time.ts | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/package-lock.json b/package-lock.json index d829cc9..d5bfc8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "discord-player": "^6.7.1", "discord.js": "^14.16.2", "mediaplex": "^0.0.9", + "moment-timezone": "^0.5.45", "sqlite3": "^5.1.7", "typescript": "^5.6.2", "uuid": "^10.0.0" @@ -3291,6 +3292,27 @@ "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", "license": "MIT" }, + "node_modules/moment": { + "version": "2.30.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", + "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==", + "license": "MIT", + "engines": { + "node": "*" + } + }, + "node_modules/moment-timezone": { + "version": "0.5.45", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.45.tgz", + "integrity": "sha512-HIWmqA86KcmCAhnMAN0wuDOARV/525R2+lOLotuGFzn4HO+FH+/645z2wx0Dt3iDv6/p61SIvKnDstISainhLQ==", + "license": "MIT", + "dependencies": { + "moment": "^2.29.4" + }, + "engines": { + "node": "*" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", diff --git a/package.json b/package.json index 31739ae..548270e 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "discord-player": "^6.7.1", "discord.js": "^14.16.2", "mediaplex": "^0.0.9", + "moment-timezone": "^0.5.45", "sqlite3": "^5.1.7", "typescript": "^5.6.2", "uuid": "^10.0.0" diff --git a/src/utils/time.ts b/src/utils/time.ts index a640cc8..bc04f6d 100644 --- a/src/utils/time.ts +++ b/src/utils/time.ts @@ -1,3 +1,5 @@ +import moment from "moment-timezone"; + /** * Parsed string adapted with TZ (locales) and format for the specified lang * @param tz Lang @@ -6,7 +8,9 @@ * @returns String */ export const showDate = (tz: string, locale: Map, date: Date) => { + const localeInfo = new Intl.Locale(tz); const formattedDate = new Intl.DateTimeFormat(tz, { + timeZone: moment.tz.zonesForCountry(localeInfo.region ?? localeInfo.baseName)[0], dateStyle: "short", timeStyle: "medium", })