diff --git a/apps/clkinfosunrise/ChangeLog b/apps/clkinfosunrise/ChangeLog index d50fb06f4..86e7a7fa8 100644 --- a/apps/clkinfosunrise/ChangeLog +++ b/apps/clkinfosunrise/ChangeLog @@ -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) diff --git a/apps/clkinfosunrise/clkinfo.js b/apps/clkinfosunrise/clkinfo.js index 71031e1d5..22c507f34 100644 --- a/apps/clkinfosunrise/clkinfo.js +++ b/apps/clkinfosunrise/clkinfo.js @@ -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==") } },