File tree Expand file tree Collapse file tree 1 file changed +12
-23
lines changed
apps/webapp/app/components/primitives Expand file tree Collapse file tree 1 file changed +12
-23
lines changed Original file line number Diff line number Diff line change @@ -22,31 +22,14 @@ export const DateTime = ({
22
22
showTimezone = false ,
23
23
} : DateTimeProps ) => {
24
24
const locales = useLocales ( ) ;
25
- const realDate = typeof date === "string" ? new Date ( date ) : date ;
26
- const resolvedOptions = Intl . DateTimeFormat ( ) . resolvedOptions ( ) ;
27
- const localTimeZone = resolvedOptions . timeZone ;
28
-
29
- const initialFormattedDateTime = formatDateTime (
30
- realDate ,
31
- timeZone ?? "UTC" ,
32
- locales ,
33
- includeSeconds ,
34
- includeTime
35
- ) ;
25
+ const [ localTimeZone , setLocalTimeZone ] = useState < string > ( "UTC" ) ;
36
26
37
- const [ formattedDateTime , setFormattedDateTime ] = useState < string > ( initialFormattedDateTime ) ;
27
+ const realDate = typeof date === " string" ? new Date ( date ) : date ;
38
28
39
29
useEffect ( ( ) => {
40
- setFormattedDateTime (
41
- formatDateTime (
42
- realDate ,
43
- timeZone ?? resolvedOptions . timeZone ,
44
- locales ,
45
- includeSeconds ,
46
- includeTime
47
- )
48
- ) ;
49
- } , [ locales , includeSeconds , realDate ] ) ;
30
+ const resolvedOptions = Intl . DateTimeFormat ( ) . resolvedOptions ( ) ;
31
+ setLocalTimeZone ( resolvedOptions . timeZone ) ;
32
+ } , [ ] ) ;
50
33
51
34
const tooltipContent = (
52
35
< div className = "flex flex-col gap-1" >
@@ -89,7 +72,13 @@ export const DateTime = ({
89
72
< SimpleTooltip
90
73
button = {
91
74
< Fragment >
92
- { formattedDateTime . replace ( / \s / g, String . fromCharCode ( 32 ) ) }
75
+ { formatDateTime (
76
+ realDate ,
77
+ timeZone ?? localTimeZone ,
78
+ locales ,
79
+ includeSeconds ,
80
+ includeTime
81
+ ) . replace ( / \s / g, String . fromCharCode ( 32 ) ) }
93
82
{ showTimezone ? ` (${ timeZone ?? "UTC" } )` : null }
94
83
</ Fragment >
95
84
}
You can’t perform that action at this time.
0 commit comments