Skip to content

Commit

Permalink
now using luxon because Date is retarded
Browse files Browse the repository at this point in the history
  • Loading branch information
raluvy95 committed Apr 14, 2023
1 parent a3883a7 commit d5cfbd2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion src/utils/dateToString.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { DateTime } from "luxon"

function zero(numb: number): string {
let str = numb.toString()
if (str.length == 1) {
Expand All @@ -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] + ')' : ''}`
}

0 comments on commit d5cfbd2

Please sign in to comment.