Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized clock script #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions assets/js/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
// ┴ ┴┴ ┴└─┘
// Set time and Date

let last_saved_minute = 61;
window.onload = displayClock();

function displayClock() {
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
writeTime()
setInterval(() => {
let d = new Date();
if(d.getMinutes() == last_saved_minute) return;
last_saved_minute = d.getMinutes()
writeTime()
},1000);
}

var d = new Date();
function writeTime() {
let d = new Date();
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

var mm = monthNames[d.getMonth()];
var dd = d.getDate();
var min = (mins = ('0' + d.getMinutes()).slice(-2));
Expand All @@ -26,6 +38,4 @@ function displayClock() {

document.getElementById('month').innerText = mm;
document.getElementById('day').innerText = dd;

setTimeout(displayClock, 1000);
}
}