-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(design-system): use intl format for datetime inputs
Signed-off-by: ryanwolhuter <[email protected]>
- Loading branch information
1 parent
16e28ed
commit d51f809
Showing
9 changed files
with
36 additions
and
104 deletions.
There are no files selected for viewing
38 changes: 0 additions & 38 deletions
38
...es/design-system/src/connect/components/date-time-input/date-time-local-input.stories.tsx
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
packages/design-system/src/connect/components/date-time-input/date-time-local-input.tsx
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/design-system/src/connect/components/date-time-input/index.ts
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import { formatInTimeZone } from "date-fns-tz/formatInTimeZone"; | ||
import { format } from "date-fns/format"; | ||
|
||
/** | ||
* The html datetime local input requires this specific format | ||
*/ | ||
export function convertToDateTimeLocalFormat(date: Date | string = new Date()) { | ||
return format(date, "yyyy-MM-dd'T'HH:mm"); | ||
} | ||
export function formatDateForDisplay(date: Date | string, displayTime = true) { | ||
const formatString = displayTime ? "yyyy/MM/dd, HH:mm:ss zzz" : "yyyy/MM/dd"; | ||
|
||
return formatInTimeZone(date, "UTC", formatString); | ||
return formatInTimeZone(date, getTimeZone(), formatString); | ||
} | ||
|
||
export function isISODate(str: string) { | ||
if (!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(str)) return false; | ||
const d = new Date(str); | ||
return d instanceof Date && !isNaN(d.getTime()) && d.toISOString() === str; | ||
} | ||
|
||
export function getTimeZone() { | ||
return Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
} | ||
|
||
export function isoDateStringToDateInput( | ||
isoDateString: string, | ||
withTime = false, | ||
) { | ||
const format = withTime ? "yyyy-MM-dd'T'HH:mm:ss.SSS" : "yyyy-MM-dd"; | ||
const timeZone = getTimeZone(); | ||
return formatInTimeZone(isoDateString, timeZone, format); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.