-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
1bd3ffb
commit 8dcddc9
Showing
3 changed files
with
11 additions
and
22 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
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,34 +1,22 @@ | ||
import dayjs from "dayjs"; | ||
import advancedFormat from "dayjs/plugin/advancedFormat"; | ||
import customParseFormat from "dayjs/plugin/customParseFormat"; | ||
import localizedFormat from "dayjs/plugin/localizedFormat"; | ||
import timezone from "dayjs/plugin/timezone"; | ||
|
||
dayjs.extend(timezone); | ||
dayjs.extend(advancedFormat); | ||
dayjs.extend(customParseFormat); | ||
dayjs.extend(localizedFormat); | ||
dayjs.extend(timezone); | ||
|
||
// Convert "2024-02-21" to "February 21, 2024" | ||
export function formatDate(dateStr: string | null): string { | ||
if (!dateStr || dateStr.length !== 10) { | ||
console.warn("invalid date string provided for parse"); | ||
return ""; | ||
} | ||
|
||
const parts = dateStr.split("-"); | ||
|
||
if (parts.length !== 3) { | ||
if (!dateStr || !dayjs(dateStr, "YYYY-MM-DD", true).isValid()) { | ||
console.warn("invalid date string provided for parse"); | ||
return ""; | ||
} | ||
|
||
const [year, month, day] = parts.map(Number); | ||
// Create a new Date object using the local time | ||
const date = new Date(year, month - 1, day); | ||
|
||
const options: Intl.DateTimeFormatOptions = { | ||
year: "numeric", | ||
month: "long", | ||
day: "numeric", | ||
}; | ||
return date.toLocaleDateString("en-US", options); | ||
return dayjs(dateStr).format("LL"); | ||
} | ||
|
||
export const getConfiguredDayJs = () => dayjs; |
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