From d5cfbd23dadb95f2074b2b9ad3d31b6cdcb51625 Mon Sep 17 00:00:00 2001 From: raluvy95 Date: Fri, 14 Apr 2023 12:30:59 +0300 Subject: [PATCH] now using luxon because Date is retarded --- package.json | 2 ++ src/utils/dateToString.ts | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1cae50c..e59e52c 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "devDependencies": { "@types/better-sqlite3": "^7.6.3", "@types/cross-spawn": "^6.0.2", + "@types/luxon": "^3.3.0", "@types/node": "^18.14.6", "@types/node-fetch": "^2.6.2", "nodemon": "^2.0.21", @@ -30,6 +31,7 @@ "dotenv": "^16.0.3", "eris": "^0.17.2", "eris-collect": "^1.1.1", + "luxon": "^3.3.0", "node-fetch": "^2.6.9", "quick.db": "^9.0.8", "rss-to-json": "^2.1.1" diff --git a/src/utils/dateToString.ts b/src/utils/dateToString.ts index 62ae603..d4ce2ce 100644 --- a/src/utils/dateToString.ts +++ b/src/utils/dateToString.ts @@ -1,3 +1,5 @@ +import { DateTime } from "luxon" + function zero(numb: number): string { let str = numb.toString() if (str.length == 1) { @@ -7,6 +9,6 @@ function zero(numb: number): string { } export function dateToString(date: Date, opts?: { clockOnly?: boolean, includesTimezone?: boolean, timezone?: string }): string { - date = new Date(date.toLocaleString(undefined, { timeZone: opts?.timezone })) + date = DateTime.fromJSDate(date).setZone(opts?.timezone).toJSDate() return `${opts?.clockOnly ? '' : date.toDateString() + ' '}${date.getHours()}:${zero(date.getMinutes())}${!opts?.clockOnly ? ":" + zero(date.getSeconds()) : ''}${opts?.includesTimezone ? ' (' + date.toLocaleTimeString('en-us', { timeZoneName: 'short', timeZone: opts.timezone }).split(' ')[2] + ')' : ''}` } \ No newline at end of file