File tree Expand file tree Collapse file tree 3 files changed +35
-23
lines changed
Expand file tree Collapse file tree 3 files changed +35
-23
lines changed Original file line number Diff line number Diff line change 1+ 'use client' ;
2+
3+ import { INTL_LOCALE } from '@/lib/utils' ;
4+
5+ type DateTimeProps = {
6+ options ?: Intl . DateTimeFormatOptions ;
7+ timestamp : number ;
8+ type ?: 'date' | 'datetime' ;
9+ } ;
10+
11+ export function DateTime ( {
12+ options,
13+ timestamp,
14+ type = 'datetime' ,
15+ } : DateTimeProps ) {
16+ const date = new Date ( timestamp ) ;
17+
18+ const formatted =
19+ type === 'date'
20+ ? date . toLocaleDateString ( INTL_LOCALE , options )
21+ : date . toLocaleString ( INTL_LOCALE , options ) ;
22+
23+ return < time dateTime = { date . toISOString ( ) } > { formatted } </ time > ;
24+ }
Original file line number Diff line number Diff line change @@ -13,12 +13,9 @@ import {
1313} from '@/components/ui/card' ;
1414import { fetchPkgbuilds , PkgbuildMap } from '@/lib/github' ;
1515import { BriefPackageList , PackageDetails , PackageRepo } from '@/lib/types' ;
16- import {
17- getDownloadMirrorUrl ,
18- getPkgverWithoutBuildnum ,
19- INTL_LOCALE ,
20- } from '@/lib/utils' ;
16+ import { getDownloadMirrorUrl , getPkgverWithoutBuildnum } from '@/lib/utils' ;
2117
18+ import { DateTime } from './DateTime' ;
2219import { HoverPrefetchLink } from './HoverPrefetchLink' ;
2320
2421type PackageDetailsComponentProps = {
@@ -93,14 +90,10 @@ export default async function PackageDetailsComponent({
9390 </ DetailRow >
9491 < DetailRow label = "Build Date" >
9592 { pkg . pkg_builddate ? (
96- < time
97- dateTime = { new Date ( pkg . pkg_builddate * 1000 ) . toISOString ( ) }
98- suppressHydrationWarning
99- >
100- { new Date ( pkg . pkg_builddate * 1000 ) . toLocaleString (
101- INTL_LOCALE
102- ) }
103- </ time >
93+ < DateTime
94+ timestamp = { pkg . pkg_builddate * 1000 }
95+ type = "datetime"
96+ />
10497 ) : (
10598 'unknown'
10699 ) }
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ import {
1717 TableRow ,
1818} from '@/components/ui/table' ;
1919import { BriefPackage , BriefPackageList } from '@/lib/types' ;
20- import { INTL_LOCALE } from '@/lib/utils' ;
20+
21+ import { DateTime } from './DateTime' ;
2122
2223interface PackageSearchResultsTableProps {
2324 onArchitectureClick ?: ( arch : string ) => void ;
@@ -91,15 +92,9 @@ export default function PackageTable({
9192 } ,
9293 } ) ,
9394 columnHelper . accessor ( 'pkg_builddate' , {
94- cell : ( { getValue} ) => {
95- const buildDate = getValue ( ) ;
96- const date = new Date ( buildDate * 1000 ) ;
97- return (
98- < time dateTime = { date . toISOString ( ) } suppressHydrationWarning >
99- { date . toLocaleDateString ( INTL_LOCALE ) }
100- </ time >
101- ) ;
102- } ,
95+ cell : ( { getValue} ) => (
96+ < DateTime timestamp = { getValue ( ) * 1000 } type = "date" />
97+ ) ,
10398 header : 'Last Updated' ,
10499 meta : {
105100 headerClassName : 'md:w-[200px]' ,
You can’t perform that action at this time.
0 commit comments