Skip to content

Commit

Permalink
Fix period calculation in experience
Browse files Browse the repository at this point in the history
  • Loading branch information
maciekiwaniuk committed Jan 23, 2025
1 parent ca2fd31 commit c92cdc0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
39 changes: 27 additions & 12 deletions components/Experience/Experience.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,39 +91,54 @@ function getTranslatedPeriod(startDate: Date, endDate: Date | null): string {
if (!endDate) {
endDate = new Date();
}
const yearsDifference = endDate.getFullYear() - startDate.getFullYear();
const monthsDifference = (endDate.getMonth() - startDate.getMonth()) + 1;
let yearsDifference = endDate.getFullYear() - startDate.getFullYear();
let monthsDifference = endDate.getMonth() - startDate.getMonth();
if (monthsDifference < 0) {
yearsDifference -= 1;
monthsDifference += 12;
}
if (endDate.getDate() >= startDate.getDate()) {
monthsDifference += 1;
}
if (monthsDifference === 12) {
yearsDifference += 1;
monthsDifference = 0;
}
let yearsString = '';
if (yearsDifference === 1) {
yearsString = t('experience.year');
}
else if (yearsDifference > 1 && ![12, 13, 14].includes(yearsDifference % 100) && [2, 3, 4].includes(yearsDifference % 10)) {
} else if (
yearsDifference > 1 &&
![12, 13, 14].includes(yearsDifference % 100) &&
[2, 3, 4].includes(yearsDifference % 10)
) {
yearsString = t('experience.yearsFirstForm');
}
else if (yearsDifference > 1) {
} else if (yearsDifference > 1) {
yearsString = t('experience.yearsSecondForm');
}
let monthsString = '';
if (monthsDifference === 1) {
monthsString = t('experience.month');
}
else if (monthsDifference > 1) {
} else if (monthsDifference > 1) {
monthsString = t('experience.months');
}
if (yearsString && monthsString) {
return `(${yearsDifference} ${yearsString} ${monthsDifference} ${monthsString})`;
}
else if (yearsString) {
} else if (yearsString) {
return `(${yearsDifference} ${yearsString})`;
}
else if (monthsString) {
} else if (monthsString) {
return `(${monthsDifference} ${monthsString})`;
}
return '';
}
</script>

<template>
Expand Down
1 change: 1 addition & 0 deletions components/Experience/ExperienceItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import TechnologyElement from '~/components/TechnologyElement.vue';
import ExperienceTimeline from '~/components/Experience/ExperienceTimeline.vue';
import { useCursorHover } from '~/directives/useCursorHover';
import { useThemeStore } from '~/stores/theme';
import type { TechnologyType } from '~/types/TechnologyType';
Expand Down

0 comments on commit c92cdc0

Please sign in to comment.