Skip to content

Commit

Permalink
refactor: Change base date to be a string
Browse files Browse the repository at this point in the history
  • Loading branch information
allangalera committed Nov 2, 2024
1 parent 26796f0 commit 594e6c9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
22 changes: 11 additions & 11 deletions src/data/experiences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const experiences = [
{
title: 'Frontend Engineer',
location: 'Berlin, Germany',
startDate: new Date('2023-06-01'),
startDate: '2023-06-01',
tags: ['Vuejs', 'Contentful', 'Nuxt'],
},
],
Expand All @@ -24,16 +24,16 @@ export const experiences = [
description:
'With the new role I started mentoring my less experienced co-workers and also being recognized as a tech reference to the others around, providing solutions and giving life to ideas.',
location: 'Sao Paulo, Brazil',
startDate: new Date('2022-04'),
endDate: new Date('2023-04-28'),
startDate: '2022-04',
endDate: '2023-04-28',
tags: ['Reactjs', 'Cypress', 'Directus', 'Strapi', 'Agile'],
},
{
title: 'Frontend Developer II',
description: 'Worked on the help center of a food delivery web app.',
location: 'Sao Paulo, Brazil',
endDate: new Date('2022-04'),
startDate: new Date('2020-10'),
endDate: '2022-04',
startDate: '2020-10',
tags: ['Reactjs', 'Cypress', 'Strapi', 'Agile'],
},
],
Expand All @@ -48,8 +48,8 @@ export const experiences = [
description:
'I worked with two clients: one that was an e-comerce and other that I architected a website and developed an app.',
location: 'Sao Paulo, Brazil',
startDate: new Date('2019-07'),
endDate: new Date('2020-10'),
startDate: '2019-07',
endDate: '2020-10',
tags: ['Angular', 'Vuejs', 'Nextjs', 'Reactjs', 'React Native'],
},
],
Expand All @@ -64,8 +64,8 @@ export const experiences = [
location: 'Rio de Janeiro, Brazil',
description:
'My job at TUUT was to create high fidelity design websites.',
startDate: new Date('2019-02'),
endDate: new Date('2019-07'),
startDate: '2019-02',
endDate: '2019-07',
tags: ['Wordpress'],
},
],
Expand All @@ -77,8 +77,8 @@ export const experiences = [
{
title: 'Full-Stack Developer',
location: 'Rio de Janeiro, Brazil',
startDate: new Date('2016-10'),
endDate: new Date('2019-01'),
startDate: '2016-10',
endDate: '2019-01',
description:
'Most of my job was to build high fidelity design websites. But I also had a project that I had to create a whole ecosystem to make a inventory management system for a small market. For that we had to develop a desktop app, a web app and a mobile app.',
tags: ['Wordpress', 'React Native', 'Electron', 'Laravel'],
Expand Down
6 changes: 4 additions & 2 deletions src/modules/resume/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ type NonEmptyArray<T> = [T, ...T[]];
export type ExperienceTypes =
(typeof ExperienceTypesOptions)[keyof typeof ExperienceTypesOptions];

export type JobDate = string;

export type BaseJobTitle = {
title: string;
skills?: NonEmptyArray<string>;
Expand All @@ -13,8 +15,8 @@ export type BaseJobTitle = {
};

export type JobPermanence = {
endDate?: Date;
startDate: Date;
endDate?: JobDate;
startDate: JobDate;
};

export type JobTitles = BaseJobTitle & JobPermanence;
Expand Down
45 changes: 26 additions & 19 deletions src/modules/resume/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
intervalToDuration,
closestTo,
differenceInDays,
parseISO,
} from 'date-fns';
import type {
Experience,
Expand All @@ -12,29 +13,25 @@ import type {
} from '@/modules/resume/types';
import { ExperienceTypesOptions } from '../constants';

export const getISODate = (dt?: Date): Date => {
if (!dt) {
dt = new Date();
export const showDate = (date?: string | Date) => {
let isoDate;
if (date instanceof Date) {
isoDate = date ?? parseISO(new Date().toISOString());
} else {
isoDate = date ? parseISO(date) : parseISO(new Date().toISOString());
}
return new Date(dt.valueOf() + dt.getTimezoneOffset() * 60 * 1000);
};

export const showDate = (value: Date | undefined) => {
const isoDate = getISODate(value);

if (differenceInDays(isoDate, getISODate()) === 0) {
if (differenceInDays(isoDate, parseISO(new Date().toISOString())) === 0) {
return 'Present';
}

return format(isoDate, 'MMM yyyy');
};

export const period = ({ start, end }: { start: Date; end: Date }) => {
const startISO = getISODate(start);
const endISO = getISODate(end);
const duration = intervalToDuration({
start: startISO,
end: endISO,
start,
end,
});

return formatDuration(duration, { format: ['years', 'months'] });
Expand All @@ -50,8 +47,12 @@ export const calculateJobStartandEndDate = (jobTitles: JobTitles[]) => {
endDatesArray: Date[];
}>(
(acc, curr) => {
acc.startDatesArray.push(getISODate(curr.startDate));
acc.endDatesArray.push(getISODate(curr.endDate));
acc.startDatesArray.push(parseISO(curr.startDate));
acc.endDatesArray.push(
curr.endDate
? parseISO(curr.endDate)
: parseISO(new Date().toISOString()),
);
return acc;
},
{
Expand All @@ -60,8 +61,11 @@ export const calculateJobStartandEndDate = (jobTitles: JobTitles[]) => {
},
);

const startDate = closestTo(getISODate(new Date(0)), startDatesArray);
const endDate = closestTo(getISODate(), endDatesArray);
const startDate = closestTo(
parseISO(new Date(0).toISOString()),
startDatesArray,
);
const endDate = closestTo(parseISO(new Date().toISOString()), endDatesArray);

if (!startDate || !endDate) {
throw new Error('[utils][calculateJobStartandEndDate]: wrong date format');
Expand Down Expand Up @@ -92,8 +96,11 @@ export const calculateWholeExperienceTime = (experiences: Experience[]) => {
},
);

const startDate = closestTo(getISODate(new Date(0)), startDatesArray);
const endDate = closestTo(getISODate(), endDatesArray);
const startDate = closestTo(
parseISO(new Date(0).toISOString()),
startDatesArray,
);
const endDate = closestTo(parseISO(new Date().toISOString()), endDatesArray);

if (!startDate || !endDate) {
throw new Error('[utils][calculateWholeExperienceTime]: wrong date format');
Expand Down

0 comments on commit 594e6c9

Please sign in to comment.