personal-website/layouts/shortcodes/footer-timer.html
Adora Laura Kalb 38783f27c2
All checks were successful
ci/woodpecker/push/deploy-rsync Pipeline was successful
ci/woodpecker/push/deploy-netlify Pipeline was successful
ci/woodpecker/push/deploy-cloudflare Pipeline was successful
update timer
2024-05-23 07:06:41 +02:00

64 lines
1.9 KiB
HTML

^-^ <a id="inconspicuous-timer-a" href="/images/secret.jpg"><i id="inconspicuous-timer"></i></a>
<script>
function getTimeSince(dateString) {
// Parse the input date string into a Date object
const startDate = new Date(dateString);
// Get the current date
const currentDate = new Date();
// Calculate the differences in each unit
let years = currentDate.getFullYear() - startDate.getFullYear();
let months = currentDate.getMonth() - startDate.getMonth();
let days = currentDate.getDate() - startDate.getDate();
let hours = currentDate.getHours() - startDate.getHours();
let minutes = currentDate.getMinutes() - startDate.getMinutes();
// Adjust for negative month difference
if (months < 0) {
years--;
months += 12;
}
// Adjust for negative day difference
if (days < 0) {
months--;
let prevMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0).getDate();
days += prevMonth;
}
// Adjust for negative hour difference
if (hours < 0) {
days--;
hours += 24;
}
// Adjust for negative minute difference
if (minutes < 0) {
hours--;
minutes += 60;
}
return {
years: years,
months: months,
days: days,
hours: hours,
minutes: minutes
};
}
// Set the date we're counting up from
const startDate = new Date("Dec 28, 2023 16:34:56");
function updateHtml() {
const result = getTimeSince("Dec 28, 2023 16:34:56");
const timerElement = document.getElementById("inconspicuous-timer")
timerElement.innerHTML = `${result.years}y ${result.months}m ${result.days}d ${result.hours}h ${result.minutes}min`;
}
updateHtml()
var x = setInterval(updateHtml, 10000);
</script>