Skip to content

Commit f187190

Browse files
author
Matheus Jardim Bernardes
committed
update position duration dinamically
1 parent f23d2cf commit f187190

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

assets/js/script.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,42 @@ function updateAge() {
3030

3131
setInterval(updateAge, 1000);
3232

33+
// Update work periods
34+
function calculatePeriod(startDate) {
35+
const now = new Date();
36+
const start = new Date(startDate);
37+
const diffTime = Math.abs(now - start);
38+
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
39+
40+
const years = Math.floor(diffDays / 365);
41+
const months = Math.floor((diffDays % 365) / 30);
42+
43+
if (years > 0 && months > 0) {
44+
return `${years} yr${years > 1 ? 's' : ''} ${months} mo${months > 1 ? 's' : ''}`;
45+
} else if (years > 0) {
46+
return `${years} yr${years > 1 ? 's' : ''}`;
47+
} else {
48+
return `${months} mo${months > 1 ? 's' : ''}`;
49+
}
50+
}
51+
52+
function updateWorkPeriods() {
53+
const professorElement = document.getElementById("professor-period");
54+
const ctoElement = document.getElementById("cto-period");
55+
56+
if (professorElement) {
57+
professorElement.innerHTML = calculatePeriod(new Date(2024, 1, 1)); // Feb 2024
58+
}
59+
60+
if (ctoElement) {
61+
ctoElement.innerHTML = calculatePeriod(new Date(2016, 11, 1)); // Dec 2016
62+
}
63+
}
64+
65+
// Update periods initially and then every hour
66+
updateWorkPeriods();
67+
setInterval(updateWorkPeriods, 3600000); // Update every hour
68+
3369
// element toggle function
3470
const elementToggleFunc = function (elem) {
3571
elem.classList.toggle("active");

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ <h3 class="h3">Experience</h3>
667667
<ol class="timeline-list">
668668
<li class="timeline-item">
669669
<h4 class="h4 timeline-item-title">Professor at Atitus</h4>
670-
<span>Feb 2024 - Present · 3 mos</span>
670+
<span>Feb 2024 - Present · <span id="professor-period">3 mos</span></span>
671671
<!-- <p class="timeline-text">-->
672672
<!-- TODO-->
673673
<!-- </p>-->
@@ -677,7 +677,7 @@ <h4 class="h4 timeline-item-title">Professor at Atitus</h4>
677677
<h4 class="h4 timeline-item-title">
678678
CTO at Conceptu Protótipos & Sistemas
679679
</h4>
680-
<span>Dec 2016 - Present · 7 yrs 5 mos</span>
680+
<span>Dec 2016 - Present · <span id="cto-period">7 yrs 5 mos</span></span>
681681
<!-- <p class="timeline-text">-->
682682
<!-- TODO-->
683683
<!-- </p>-->

0 commit comments

Comments
 (0)