find timezone based on locale
All checks were successful
Lint and Format Check / lint-and-format (pull_request) Successful in 10s

This commit is contained in:
Mylloon 2024-09-24 19:32:23 +02:00
parent a08d0c0e9b
commit f07d4d6756
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 27 additions and 0 deletions

22
package-lock.json generated
View file

@ -17,6 +17,7 @@
"discord-player": "^6.7.1", "discord-player": "^6.7.1",
"discord.js": "^14.16.2", "discord.js": "^14.16.2",
"mediaplex": "^0.0.9", "mediaplex": "^0.0.9",
"moment-timezone": "^0.5.45",
"sqlite3": "^5.1.7", "sqlite3": "^5.1.7",
"typescript": "^5.6.2", "typescript": "^5.6.2",
"uuid": "^10.0.0" "uuid": "^10.0.0"
@ -3291,6 +3292,27 @@
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==",
"license": "MIT" "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": { "node_modules/ms": {
"version": "2.1.3", "version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",

View file

@ -25,6 +25,7 @@
"discord-player": "^6.7.1", "discord-player": "^6.7.1",
"discord.js": "^14.16.2", "discord.js": "^14.16.2",
"mediaplex": "^0.0.9", "mediaplex": "^0.0.9",
"moment-timezone": "^0.5.45",
"sqlite3": "^5.1.7", "sqlite3": "^5.1.7",
"typescript": "^5.6.2", "typescript": "^5.6.2",
"uuid": "^10.0.0" "uuid": "^10.0.0"

View file

@ -1,3 +1,5 @@
import moment from "moment-timezone";
/** /**
* Parsed string adapted with TZ (locales) and format for the specified lang * Parsed string adapted with TZ (locales) and format for the specified lang
* @param tz Lang * @param tz Lang
@ -6,7 +8,9 @@
* @returns String * @returns String
*/ */
export const showDate = (tz: string, locale: Map<string, unknown>, date: Date) => { export const showDate = (tz: string, locale: Map<string, unknown>, date: Date) => {
const localeInfo = new Intl.Locale(tz);
const formattedDate = new Intl.DateTimeFormat(tz, { const formattedDate = new Intl.DateTimeFormat(tz, {
timeZone: moment.tz.zonesForCountry(localeInfo.region ?? localeInfo.baseName)[0],
dateStyle: "short", dateStyle: "short",
timeStyle: "medium", timeStyle: "medium",
}) })