From 593c3836814c4f2ff2e3cdc220c2528b7f339f8e Mon Sep 17 00:00:00 2001 From: etherware-novice <73374039+etherware-novice@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:00:22 -0500 Subject: [PATCH] self-rolled swatch clock --- _includes/swatchclock.html | 3 ++- assets/js/swatch.js | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 assets/js/swatch.js diff --git a/_includes/swatchclock.html b/_includes/swatchclock.html index 3076a8e..9c18147 100644 --- a/_includes/swatchclock.html +++ b/_includes/swatchclock.html @@ -1,3 +1,4 @@ time: @000 - + + diff --git a/assets/js/swatch.js b/assets/js/swatch.js new file mode 100644 index 0000000..6b5bcaf --- /dev/null +++ b/assets/js/swatch.js @@ -0,0 +1,26 @@ +function getSwatch(showCenti = true) { + var date = new Date(); + var hours = date.getUTCHours(); + var minutes = date.getUTCMinutes(); + var seconds = date.getUTCSeconds(); + var ms = date.getUTCMilliseconds(); + + hours = hours == 23 ? 0 : hours + 1; + + var timeMS = ((hours * 60 + minutes) * 60 + seconds) * 1000 + ms; + var trueSwatch = Math.abs(timeMS / 86400); + + if (showCenti) { + return trueSwatch.toFixed(2); + } + else { + return Math.floor(trueSwatch); + } +} + +var disp = document.getElementById('swatchClock'); +function updateSwatch() { + disp.innerHTML = '@' + getSwatch(); +} +setInterval(updateSwatch, 864); +