Skip to content

Commit

Permalink
change birthday to age
Browse files Browse the repository at this point in the history
  • Loading branch information
levg34 committed Nov 1, 2023
1 parent dfc4263 commit 23b4e37
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions frontend/src/cv-sections/CvHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Avatar, Card } from '@suid/material'
import { Header } from '../types'
import { For, Show } from 'solid-js'
import Hidden from './Hidden'
import { calculateAge } from '../utils'

export default (header: Header) => (
<Card>
Expand All @@ -24,9 +25,10 @@ export default (header: Header) => (

<ul>
<li>
<strong>Birthday:</strong>
<Show when={header.infos.birthday !== null} fallback={<Hidden key={'header.infos.birthday'} />}>
{header.infos.birthday}
<strong>Age:</strong>
<Show when={header.infos.birthday !== null}>{calculateAge(header.infos.birthday)} years</Show>
<Show when={header.infos.birthday === null}>
<Hidden key={'header.infos.birthday'} />
</Show>
</li>
<li>
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function calculateAge(birthday: string | number | Date) {
const birthDate = new Date(birthday)
const currentDate = new Date()
let age = currentDate.getFullYear() - birthDate.getFullYear()

// Adjust age if birthday hasn't occurred yet this year
if (currentDate < new Date(currentDate.getFullYear(), birthDate.getMonth(), birthDate.getDate())) {
age--
}

return age
}

0 comments on commit 23b4e37

Please sign in to comment.