customisable seconds in the widget

This commit is contained in:
2024-06-12 15:29:31 +03:00
parent ea64a55218
commit 235b11259a
2 changed files with 56 additions and 18 deletions

View File

@@ -3,35 +3,48 @@
* https://gitlab.com/zlax/dtime-js
*/
function az(x) {
if (x < 10)
return "0"+x;
return x;
function addZero(numeral) {
if (numeral < 10)
return "0"+numeral;
return numeral;
}
function dtime(gregorianDate,resultar="default") {
// Easter Island Winter Time Zone offset (-5*60*60*1000)
var date = new Date(gregorianDate.getTime()-18000000);
var christianMSDay = date.valueOf() % 86400000;
var ds = (1 / (864 / christianMSDay));
var h = Math.floor(ds/10000);
ds%= 10000;
var m = Math.floor(ds/100);
ds%= 100;
var s = Math.floor(ds);
if (typeof eastertime != "undefined") {
// Easter Island Winter Time Zone offset (-5*60*60*1000)
var date = new Date(gregorianDate.getTime()-18000000);
var christianMSDay = date.valueOf() % 86400000;
} else {
// Christian Time Zone calculation
var date = new Date(gregorianDate.getTime());
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
var ms = date.getMilliseconds();
var christianMSDay = h*3600000+m*60000+s*1000+ms;
}
var erisianSecondsDay = (christianMSDay/864);
var hour = Math.floor(erisianSecondsDay/10000);
erisianSecondsDay %= 10000;
var minute = Math.floor(erisianSecondsDay/100);
erisianSecondsDay %= 100;
var second = Math.floor(erisianSecondsDay);
switch (resultar) {
case "seconds":
return h+":"+az(m)+":"+az(s);
return hour+":"+addZero(minute)+":"+addZero(second);
break;
default:
return h+":"+az(m);
return hour+":"+addZero(minute);
break;
}
}
function go() {
document.getElementById("dtime").innerHTML = dtime(new Date(), "seconds");
if (typeof widgetsec != "undefined")
document.getElementById("dtime").innerHTML = dtime(new Date(), "seconds");
else
document.getElementById("dtime").innerHTML = dtime(new Date());
}
window.onload = function() {