-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix timer button rolling over after 24h (#13148)
* Fix timer button rolling over after 24h * Use padStart function. --------- Co-authored-by: Dombi Attila <[email protected]>
- Loading branch information
1 parent
12eb324
commit 0c9ffc7
Showing
3 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
16 changes: 14 additions & 2 deletions
16
frontend/src/app/features/work-packages/components/wp-timer-button/time-formatter.helper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
import * as moment from 'moment/moment'; | ||
|
||
function paddedNumber(input:number):string { | ||
return input.toString().padStart(2, '0'); | ||
} | ||
|
||
export function formatElapsedTime(startTime:string):string { | ||
const start = moment(startTime); | ||
const now = moment(); | ||
const offset = moment(now).diff(start); | ||
const duration = now.diff(start, 'seconds'); | ||
|
||
const hours = Math.floor(duration / 3600); | ||
const minutes = Math.floor((duration - (hours * 3600)) / 60); | ||
const seconds = duration - (hours * 3600) - (minutes * 60); | ||
|
||
return moment.utc(offset).format('HH:mm:ss'); | ||
return [ | ||
paddedNumber(hours), | ||
paddedNumber(minutes), | ||
paddedNumber(seconds), | ||
].join(':'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters