1
0
Fork 0

Added more functions to get the time, time str or remaining minutes.

master
David Peer 2022-02-26 09:24:42 +01:00
parent c6c86213d1
commit ef31fd4f01
2 changed files with 18 additions and 3 deletions

View File

@ -26,6 +26,7 @@ The following functions are available:
- decreaseTimer(int) -> void - decreaseTimer(int) -> void
- getRemainingMinutes() -> int - getRemainingMinutes() -> int
- getRemainingTime() -> DateTime - getRemainingTime() -> DateTime
- getRemainingTimeStr() -> str
Example to increase the timer by 5 and ensure that its started: Example to increase the timer by 5 and ensure that its started:
```Javascript ```Javascript

View File

@ -131,16 +131,30 @@
var diff = settings.goal - now; var diff = settings.goal - now;
return Math.ceil(diff / (1000*60)); return Math.ceil(diff / (1000*60));
}, getRemainingTime: function(){ }, getRemainingTimeStr: function(){
settings = storage.readJSON("widtmr.json",1)||{started: false};
if(!settings.started){ if(!settings.started){
return; return;
} }
var now = new Date(); var now = new Date();
var diff = settings.goal - now; var diff = settings.goal - now;
return getTime(diff); var timeStr = getTime(diff);
if(diff < 3600000){
timeStr = timeStr.substring(3); // remove hour part 00:00:00 -> 00:00
}
return timeStr;
}, getRemainingTime: function(){
settings = storage.readJSON("widtmr.json",1)||{started: false};
if(!settings.started){
return;
} }
var now = new Date();
var diff = settings.goal - now;
return diff;
}
}; };
// set width correctly, start countdown each second // set width correctly, start countdown each second