File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ <script setup lang="ts">
2+ const appConfig = useAppConfig ();
3+
4+ const props = defineProps <{
5+ date: string ;
6+ }>();
7+
8+ const parsedDate = computed (() => {
9+ const dateStr = props .date ;
10+ // Handle YYYY-MM-DD format to avoid timezone issues
11+ if (/ ^ \d {4} -\d {2} -\d {2} $ / .test (dateStr )) {
12+ const [year, month, day] = dateStr .split (" -" ).map (Number );
13+ return new Date (year , month - 1 , day );
14+ }
15+ return new Date (dateStr );
16+ });
17+
18+ const formattedDate = computed (() =>
19+ parsedDate .value .toLocaleDateString (
20+ appConfig .date .locale ,
21+ appConfig .date .options ,
22+ ),
23+ );
24+
25+ const datetimeAttr = computed (() => {
26+ // For date-only inputs, use the original string to avoid timezone drift
27+ if (/ ^ \d {4} -\d {2} -\d {2} $ / .test (props .date )) {
28+ return props .date ;
29+ }
30+ return parsedDate .value .toISOString ();
31+ });
32+ </script >
33+
34+ <template >
35+ <time :datetime =" datetimeAttr" :title =" datetimeAttr" >{{ formattedDate }}</time >
36+ </template >
You can’t perform that action at this time.
0 commit comments