Change 3rd mode to show the time to next sunrise/sunset time (not actual time)

pull/2381/head
Gordon Williams 2022-12-09 13:31:55 +00:00
parent a115c3f862
commit 870ecae41c
2 changed files with 12 additions and 6 deletions

View File

@ -1,4 +1,4 @@
0.01: New App!
0.02: Use 'modules/suncalc.js' to avoid it being copied 8 times for different apps
Add a 'time' clockinfo that also displays a percentage of day left
0.03: Change 3rd mode to show the next sunrise/sunset time (not actual time)
0.03: Change 3rd mode to show the time to next sunrise/sunset time (not actual time)

View File

@ -47,19 +47,25 @@
get : () => {
calculate();
let day = true;
let v = 0;
let d = date.getTime();
let dayLength = sunset.getTime()-sunrise.getTime();
let timeUntil, timeTotal;
if (d < sunrise.getTime()) {
day = false; // early morning
v = 100 - Math.round(100 * (sunrise.getTime()-d) / (86400000-dayLength));
timePast = sunrise.getTime()-d;
timeTotal = 86400000-dayLength;
} else if (d > sunset.getTime()) {
day = false; // evening
v = Math.round(100 * (d-sunset.getTime()) / (86400000-dayLength));
timePast = d-sunset.getTime();
timeTotal = 86400000-dayLength;
} else { // day!
v = Math.round(100 * (d-sunrise.getTime()) / dayLength);
timePast = d-sunrise.getTime();
timeTotal = dayLength;
}
return { text : locale.time(day ? sunset.getTime() : sunrise.getTime(),1), v : v, min : 0, max : 100,
let v = Math.round(100 * timePast / timeTotal);
let minutesTo = (timeTotal-timePast)/60000;
return { text : (minutesTo>90) ? (Math.round(minutesTo/60)+"h") : (Math.round(minutesTo)+"m"),
v : v, min : 0, max : 100,
img : day ? atob("GBiBAAAYAAAYAAAYAAgAEBwAOAx+MAD/AAH/gAP/wAf/4Af/4Of/5+f/5wf/4Af/4AP/wAH/gAD/AAx+MBwAOAgAEAAYAAAYAAAYAA==") : atob("GBiBAAfwAA/8AAP/AAH/gAD/wAB/wAB/4AA/8AA/8AA/8AAf8AAf8AAf8AAf8AA/8AA/8AA/4AB/4AB/wAD/wAH/gAf/AA/8AAfwAA==")
}
},