Skip to content

Commit

Permalink
Shorten duration format
Browse files Browse the repository at this point in the history
  • Loading branch information
Chad Johnson committed Jun 24, 2024
1 parent 611873d commit b7b4905
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ <h1>Li Time Battery Status</h1>
if(current > 0) {
let duration = Math.abs((capacityAh - remianingAh) / current).toFixed(3);
let hours = Math.floor(duration);
let minutes = Math.round((duration - hours) * 60);
state = fmt.format(hours) + " hours " + fmt.format(minutes) + " minutes till charged";
let minutes = new String(Math.round((duration - hours) * 60)).padStart(2, '0');
state = fmt.format(hours) + "h " + minutes + "m till charged";
} else if(current < 0) {
let duration = Math.abs(remianingAh / current).toFixed(3);
let hours = Math.floor(duration);
let minutes = Math.round((duration - hours) * 60);
state = fmt.format(hours) + " hours " + fmt.format(minutes) + " minutes till depleted";
let minutes = new String(Math.round((duration - hours) * 60)).padStart(2, '0');
state = fmt.format(hours) + "h " + minutes + "m till depleted";
}

$vf.value = voltage + ' / ' + current;
Expand Down

0 comments on commit b7b4905

Please sign in to comment.