1
1
mirror of https://github.com/theoludwig/theoludwig.git synced 2025-05-29 22:37:44 +02:00

chore: maintenance

This commit is contained in:
Divlo
2021-12-04 15:52:51 +01:00
parent e5f4615f7f
commit 729e540d04
69 changed files with 10182 additions and 18460 deletions

View File

@ -0,0 +1,15 @@
import { getAge } from '../getAge'
describe('utils/getAge', () => {
it('should calculate the right age of a person', () => {
const birthDate = new Date('1980-02-20')
jest.useFakeTimers().setSystemTime(new Date('2018-03-20'))
expect(getAge(birthDate)).toBe(38)
})
it('should calculate the right age of a person (taking into account the months)', () => {
const birthDate = new Date('1980-07-20')
jest.useFakeTimers().setSystemTime(new Date('2018-03-20'))
expect(getAge(birthDate)).toBe(37)
})
})

16
utils/getAge.ts Normal file
View File

@ -0,0 +1,16 @@
export const DIVLO_BIRTHDAY = new Date('2003-03-31')
/**
* Calculates the age of a person based on their birth date
* @param birthDate
* @returns
*/
export const getAge = (birthDate: Date): number => {
const today = new Date()
let age = today.getFullYear() - birthDate.getFullYear()
const month = today.getMonth() - birthDate.getMonth()
if (month < 0 || (month === 0 && today.getDate() < birthDate.getDate())) {
age--
}
return age
}

View File

@ -0,0 +1,6 @@
import { DIVLO_BIRTHDAY, getAge } from './getAge'
export const getDefaultDescription = (): string => {
const age = getAge(DIVLO_BIRTHDAY)
return `I'm Divlo, I'm ${age} years old, I'm from France - Developer Full Stack Junior • Passionate about High-Tech`
}