mirror of
https://github.com/theoludwig/theoludwig.git
synced 2025-05-29 22:37:44 +02:00
chore: maintenance
This commit is contained in:
15
utils/__test__/getAge.test.ts
Normal file
15
utils/__test__/getAge.test.ts
Normal 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
16
utils/getAge.ts
Normal 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
|
||||
}
|
6
utils/getDefaultDescription.ts
Normal file
6
utils/getDefaultDescription.ts
Normal 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`
|
||||
}
|
Reference in New Issue
Block a user