Skip to content

Commit db59349

Browse files
committed
feat(Experience): calculated and displays the duration of each work experience in years and months
1 parent 65388ca commit db59349

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

cv.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"location": "Bandung, Indonesia",
7979
"url": "https://khansia.co.id",
8080
"startDate": "2020-09-01",
81-
"endDate": "2021-04-01",
81+
"endDate": "2020-12-01",
8282
"summary": "Assisted senior developers in building and maintaining back-end systems for mobile applications, gaining hands-on experience with back-end technologies.",
8383
"responsibilities": [
8484
"Assisted in building and maintaining back-end systems for mobile applications.",

src/components/Experience.astro

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,44 @@ import { work } from "@cv";
2626
const endYear = endDate ? new Date(endDate).getFullYear() : "Present";
2727
const isLastItem = index === work.length - 1;
2828

29+
const d1 = new Date(startDate);
30+
const d2 = endDate ? new Date(endDate) : new Date();
31+
32+
let years = d2.getFullYear() - d1.getFullYear();
33+
let months = d2.getMonth() - d1.getMonth();
34+
35+
if (months < 0) {
36+
years--;
37+
months += 12;
38+
}
39+
40+
if (!endDate) {
41+
months += 1;
42+
if (months === 12) {
43+
years += 1;
44+
months = 0;
45+
}
46+
}
47+
48+
const durationParts = [];
49+
if (years > 0) {
50+
durationParts.push(`${years} yr${years > 1 ? "s" : ""}`);
51+
}
52+
if (months > 0) {
53+
durationParts.push(`${months} mo${months > 1 ? "s" : ""}`);
54+
}
55+
const duration = durationParts.join(" ");
56+
2957
return (
3058
<>
3159
{/* Datetime */}
3260
<div class="mt-1 text-xs font-bold text-black/50 dark:text-white/50">
33-
<time datetime={startDate}>{startYear}</time>
34-
<span class="mx-1">-</span>
35-
<time datetime={endDate}>{endYear}</time>
61+
<div>
62+
<time datetime={startDate}>{startYear}</time>
63+
<span class="mx-1">-</span>
64+
<time datetime={endDate}>{endYear}</time>
65+
</div>
66+
{duration && <div class="font-normal">{duration}</div>}
3667
</div>
3768

3869
{/* Timeline */}

0 commit comments

Comments
 (0)