Skip to content

Commit 0e5e716

Browse files
committed
refactor: reuse hackathon time parsing
1 parent dc2661a commit 0e5e716

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

components/Activity/ProductCard.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,19 @@ import { FC } from 'react';
44
import { CardProps, Card, Button } from 'react-bootstrap';
55
import { formatDate } from 'web-utility';
66

7+
import { timeOf } from './Hackathon/utility';
78
import { Product } from '../../models/Hackathon';
89
import styles from '../../styles/Hackathon.module.less';
910

1011
export type ProductCardProps = Product & Omit<CardProps, 'id' | 'title'>;
1112

1213
export const ProductCard: FC<ProductCardProps> = observer(
1314
({ className = '', id, createdAt, name, sourceLink, link = sourceLink, summary, ...props }) => {
14-
const parsedCreatedAtValue =
15-
createdAt === null || createdAt === undefined || createdAt === ''
16-
? NaN
17-
: typeof createdAt === 'string'
18-
? Number.isFinite(Number(createdAt))
19-
? Number(createdAt)
20-
: Date.parse(createdAt)
21-
: Number(createdAt);
22-
const createdAtISO = Number.isFinite(parsedCreatedAtValue)
23-
? new Date(parsedCreatedAtValue).toJSON()
15+
const createdAtTime = timeOf(createdAt);
16+
const createdAtISO = Number.isFinite(createdAtTime)
17+
? new Date(createdAtTime).toJSON()
2418
: undefined;
25-
const createdAtText = Number.isFinite(parsedCreatedAtValue)
26-
? formatDate(parsedCreatedAtValue)
27-
: '';
19+
const createdAtText = Number.isFinite(createdAtTime) ? formatDate(createdAtTime) : '';
2820

2921
return (
3022
<Card className={`${styles.projectCard} ${className}`} {...props}>

0 commit comments

Comments
 (0)