feat(ui): add experience duration calculation

Add a helper function to calculate the number of years for each
experience entry based on the date range. Display the calculated
duration next to the date in the experience section.
This commit is contained in:
Dejvino 2026-05-20 09:38:43 +02:00
parent 319c01c59c
commit ec4780b20b

View File

@ -44,6 +44,25 @@ $cv_experience = array_map(function ($e) {
];
}, $cvData['experience'] ?? []);
// Helper to calculate years between start and end dates
function calculateYears($dateStr) {
// Extract start and end years, support 'present' or 'current'
$matches = [];
$dateStr = str_replace(['', '—', '', '-'], '-', $dateStr);
$parts = array_map('trim', explode('-', $dateStr, 2));
if (count($parts) < 2) {
return 0;
}
$start = (int)$parts[0];
$endRaw = strtolower($parts[1]);
$end = ($endRaw === 'present' || $endRaw === 'current') ? (int)date('Y') : (int)$endRaw;
$years = $end - $start;
if ($years <= 1) {
return "1 year";
}
return "$years years";
}
// Map education to expected structure
$cv_education = array_map(function ($e) {
return [
@ -164,7 +183,7 @@ $cv_skills = $cvData['skills'] ?? [];
<article class="cv-item">
<header class="cv-item-header">
<h3 class="cv-title"><?= $firstJob['title'] ?></h3>
<time class="cv-date"><?= $firstJob['date'] ?></time>
<span class="cv-date"><?= $firstJob['date'] ?> (<?= calculateYears($firstJob['date']) ?>)</span>
</header>
<p class="cv-org"><?= $firstJob['org'] ?></p>
<p class="cv-desc"><?= $firstJob['desc'] ?></p>
@ -199,7 +218,7 @@ $cv_skills = $cvData['skills'] ?? [];
<article class="cv-item">
<header class="cv-item-header">
<h3 class="cv-title"><?= $job['title'] ?></h3>
<time class="cv-date"><?= $job['date'] ?></time>
<span class="cv-date"><?= $job['date'] ?> (<?= calculateYears($job['date']) ?>)</span>
</header>
<p class="cv-org"><?= $job['org'] ?></p>
<p class="cv-desc"><?= $job['desc'] ?></p>