codesardine / jde

Linux desktop environment built with HTML5, CSS, JavaScript and Python.
GNU General Public License v3.0
685 stars 65 forks source link

Time parsing functionality was unneccessarily complicated #49

Closed Bystroushaak closed 6 years ago

codesardine commented 6 years ago

Thanks :+1:

Bystroushaak commented 6 years ago

Also is there a reason why you use setTimeout in this recursive manner and not setInterval?

codesardine commented 6 years ago

Yes, setTimeout only fires once, and that's all I need.

Bystroushaak commented 6 years ago

But it is not, it is called recursively. I mean, instead of

function timeDate() {
    var today = new Date();
    document.getElementById("time").innerHTML = today.toTimeString().slice(0, 8);
    document.getElementById("date").innerHTML = today.toDateString();
    var updateTime = setTimeout("timeDate()", 200);
}

you can do

function timeDate() {
    var today = new Date();
    document.getElementById("time").innerHTML = today.toTimeString().slice(0, 8);
    document.getElementById("date").innerHTML = today.toDateString();
}
setInterval(timeDate, 200);

It should be slightly more efficient.

codesardine commented 6 years ago

Ok i see what you mean, will use setInterval instead :+1:

codesardine commented 6 years ago

Now i remember why i used setTimeout recursively setInterval(timeDate, 200); does not update the clock properly and it lags behind