|
1 | | -<script module> |
| 1 | +<script lang="ts" module> |
2 | 2 | import css from "@shikijs/langs/css"; |
3 | 3 | import diff from "@shikijs/langs/diff"; |
4 | 4 | import html from "@shikijs/langs/html"; |
|
100 | 100 | ] |
101 | 101 | }; |
102 | 102 |
|
103 | | - function formatToDateTime(date: string) { |
104 | | - return new Intl.DateTimeFormat("en", { |
105 | | - dateStyle: "medium", |
106 | | - timeStyle: "short" |
107 | | - }).format(new Date(date)); |
108 | | - } |
| 103 | + const dateTimeFormatter = new Intl.DateTimeFormat("en", { |
| 104 | + dateStyle: "medium", |
| 105 | + timeStyle: "short" |
| 106 | + }); |
109 | 107 |
|
110 | 108 | type Props = { |
111 | 109 | metadata: { |
|
125 | 123 |
|
126 | 124 | let rightPartInfo = $derived<{ title: string; value: string }[]>([ |
127 | 125 | ...("answer_chosen_at" in info && info.answer_chosen_at |
128 | | - ? [{ title: "Answered at", value: formatToDateTime(info.answer_chosen_at) }] |
| 126 | + ? [{ title: "Answered at", value: dateTimeFormatter.format(new Date(info.answer_chosen_at)) }] |
129 | 127 | : []), |
130 | 128 | ...("answer_chosen_by" in info && info.answer_chosen_by |
131 | 129 | ? [{ title: "Answered by", value: info.answer_chosen_by.login }] |
|
135 | 133 | ? [ |
136 | 134 | { |
137 | 135 | title: "merged" in info && info.merged ? "Merged at" : "Closed at", |
138 | | - value: formatToDateTime(info.closed_at) |
| 136 | + value: dateTimeFormatter.format(new Date(info.closed_at)) |
139 | 137 | } |
140 | 138 | ] |
141 | 139 | : []), |
|
372 | 370 | <span class="hidden xs:block">•</span> |
373 | 371 | {/if} |
374 | 372 | {#if "createdAt" in entity} |
375 | | - <span>{formatToDateTime(entity.createdAt)}</span> |
| 373 | + <span>{dateTimeFormatter.format(new Date(entity.createdAt))}</span> |
376 | 374 | {/if} |
377 | 375 | </div> |
378 | 376 | </div> |
|
457 | 455 | <span class="mx-1 hidden text-muted-foreground xs:block">•</span> |
458 | 456 | {/if} |
459 | 457 | <span class="text-muted-foreground"> |
460 | | - {formatToDateTime(info.created_at)} |
| 458 | + {dateTimeFormatter.format(new Date(info.created_at))} |
461 | 459 | </span> |
462 | 460 | </div> |
463 | 461 | <!-- Body --> |
|
612 | 610 | <span class="mx-1 hidden text-muted-foreground xs:block">•</span> |
613 | 611 | {/if} |
614 | 612 | <span class="text-muted-foreground"> |
615 | | - {formatToDateTime(comment.created_at)} |
| 613 | + {dateTimeFormatter.format(new Date(comment.created_at))} |
616 | 614 | </span> |
617 | 615 | </div> |
618 | 616 | <!-- Body --> |
|
654 | 652 | <Step icon={GitPullRequestCreateArrow} class="text-base [&>span>svg]:text-green-500"> |
655 | 653 | <div class="flex flex-col"> |
656 | 654 | <span>Pull request open</span> |
657 | | - <span class="text-muted-foreground">{formatToDateTime(info.created_at)}</span> |
| 655 | + <span class="text-muted-foreground"> |
| 656 | + {dateTimeFormatter.format(new Date(info.created_at))} |
| 657 | + </span> |
658 | 658 | </div> |
659 | 659 | </Step> |
660 | 660 | {#each commits as commit (commit.sha)} |
|
695 | 695 | </div> |
696 | 696 | {#if commit.commit.author?.date} |
697 | 697 | <span class="text-muted-foreground"> |
698 | | - • {formatToDateTime(commit.commit.author.date)} |
| 698 | + • {dateTimeFormatter.format(new Date(commit.commit.author.date))} |
699 | 699 | </span> |
700 | 700 | {/if} |
701 | 701 | {/if} |
|
742 | 742 | <div class="absolute bottom-0 -left-8 h-4 outline outline-background"></div> |
743 | 743 | <div class="flex flex-col"> |
744 | 744 | <span>Pull request {info.merged ? "merged" : "closed"}</span> |
745 | | - <span class="text-muted-foreground">{formatToDateTime(info.closed_at)}</span> |
| 745 | + <span class="text-muted-foreground"> |
| 746 | + {dateTimeFormatter.format(new Date(info.closed_at))} |
| 747 | + </span> |
746 | 748 | </div> |
747 | 749 | </Step> |
748 | 750 | {/if} |
|
0 commit comments