-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf1250e
commit 3afd28e
Showing
9 changed files
with
142 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
/** @type {import("next").NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
webpack: (config) => { | ||
config.resolve = { | ||
...config.resolve, | ||
fallback: { | ||
fs: false, | ||
path: false, | ||
}, | ||
}; | ||
|
||
return config; | ||
}, | ||
}; | ||
|
||
module.exports = nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { getUserTimezoneOffsetInMs } from "@/scripts/Utils/DateAndTime/Helpers"; | ||
|
||
export function formatDateLong(date: Date) { | ||
const locale = new Intl.NumberFormat().resolvedOptions().locale; | ||
return date.toLocaleDateString(locale, { | ||
month: "long", | ||
day: "numeric", | ||
year: "numeric", | ||
}); | ||
} | ||
|
||
export function formatTime(date: Date) { | ||
const locale = new Intl.NumberFormat().resolvedOptions().locale; | ||
return date.toLocaleTimeString(locale, { | ||
hour: "numeric", | ||
minute: "numeric", | ||
}); | ||
} | ||
|
||
export function formatDateAndTime(date: Date) { | ||
const locale = new Intl.NumberFormat().resolvedOptions().locale; | ||
return date.toLocaleTimeString(locale, { | ||
month: "long", | ||
day: "numeric", | ||
year: "numeric", | ||
hour: "numeric", | ||
minute: "numeric", | ||
}); | ||
} | ||
|
||
export function formatDuration(ms: number) { | ||
// https://www.30secondsofcode.org/js/s/number-formatting/ | ||
if (ms < 0) ms = -ms; | ||
const time = { | ||
day: Math.floor(ms / 86_400_000), | ||
hour: Math.floor(ms / 3_600_000) % 24, | ||
minute: Math.floor(ms / 60_000) % 60, | ||
second: Math.floor(ms / 1_000) % 60, | ||
millisecond: Math.floor(ms) % 1_000, | ||
}; | ||
return Object.entries(time) | ||
.filter((val) => val[1] !== 0) | ||
.map(([key, val]) => `${val} ${key}${val !== 1 ? "s" : ""}`) | ||
.join(", "); | ||
} | ||
|
||
export function formatDateForInput(date: Date) { | ||
const dateWithOffset = new Date(date.getTime() - getUserTimezoneOffsetInMs()); | ||
const firstHalf = dateWithOffset.toISOString().split(".")[0]; | ||
const pieces = firstHalf.split(":"); | ||
pieces.pop(); | ||
return pieces.join(":"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Parse an ISO date string to a Date object or return the Date object if it is already a Date object. | ||
* | ||
* @param date The date to parse. | ||
*/ | ||
export function dp(date: Date | string) { | ||
if (typeof date === "string") { | ||
date = new Date(date); | ||
} | ||
return date; | ||
} | ||
|
||
export function isBeforeNow(date: Date) { | ||
return date.getTime() < Date.now(); | ||
} | ||
|
||
export function isAfterNow(date: Date) { | ||
return date.getTime() > Date.now(); | ||
} | ||
|
||
export function nowBetween(start: Date, end: Date) { | ||
const now = new Date(); | ||
return now >= start && now <= end; | ||
} | ||
|
||
export function getUserTimezoneOffsetInHrs() { | ||
return new Date().getTimezoneOffset() / 60; | ||
} | ||
|
||
export function getUserTimezoneOffsetInMs() { | ||
return new Date().getTimezoneOffset() * 60 * 1000; | ||
} |