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:
parent
319c01c59c
commit
ec4780b20b
27
index.php
27
index.php
@ -36,7 +36,7 @@ $extra_contact_links = $cvData['contact_links'] ?? [];
|
||||
*/
|
||||
// Map experience to expected structure
|
||||
$cv_experience = array_map(function ($e) {
|
||||
return [
|
||||
return [
|
||||
'title' => $e['title'] ?? '',
|
||||
'org' => $e['organization'] ?? '',
|
||||
'date' => $e['date'] ?? '',
|
||||
@ -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>
|
||||
@ -342,4 +361,4 @@ $cv_skills = $cvData['skills'] ?? [];
|
||||
<script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "90827cb740cd4b1db611be059f64daa9"}'></script><!-- End Cloudflare Web Analytics -->
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user