Skip to content

Commit

Permalink
Fix time formating for durations over 1h
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Jul 14, 2023
1 parent 8a335cd commit bd6fc76
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
29 changes: 19 additions & 10 deletions src/components/ControlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@ import { Match, Switch, createMemo, createSignal, onCleanup } from "solid-js";
import { throttle } from "../util";

function formatTime(seconds) {
seconds = Math.floor(seconds);
const m = Math.floor(seconds / 60);
const s = seconds % 60;
let time = '';
if (m < 10) { time += '0' }
time += `${m}:`;
if (s < 10) { time += '0' }
time += `${s}`;

return time;
let s = Math.floor(seconds);
const d = Math.floor(s / 86400);
s %= 86400;
const h = Math.floor(s / 3600);
s %= 3600;
const m = Math.floor(s / 60);
s %= 60;

if (d > 0) {
return `${zeroPad(d)}:${zeroPad(h)}:${zeroPad(m)}:${zeroPad(s)}`;
} else if (h > 0) {
return `${zeroPad(h)}:${zeroPad(m)}:${zeroPad(s)}`;
} else {
return `${zeroPad(m)}:${zeroPad(s)}`;
}
}

function zeroPad(n) {
return n < 10 ? `0${n}` : n.toString();
}

export default props => {
Expand Down
3 changes: 2 additions & 1 deletion src/less/partials/_control-bar.less
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ div.ap-control-bar {
span.ap-timer {
display: block;
flex: 0 0 auto;
width: 50px;
min-width: 50px;
margin: 0 10px;
height: 100%;
text-align: center;
font-size: 11px;
Expand Down

0 comments on commit bd6fc76

Please sign in to comment.