feat(fe): added time formatter helper
This commit is contained in:
parent
a1d14f8ee1
commit
9e690dc0c9
1 changed files with 43 additions and 0 deletions
43
resources/js/helpers/TimeFormatter.ts
Normal file
43
resources/js/helpers/TimeFormatter.ts
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
export function timeFormatter(time: String): string {
|
||||||
|
const timeArray = time.split(':');
|
||||||
|
const hours = timeArray[0];
|
||||||
|
const minutes = timeArray[1];
|
||||||
|
const seconds = timeArray[2].split('.')[0];
|
||||||
|
let stringTime = '';
|
||||||
|
if (parseInt(hours) > 0) {
|
||||||
|
stringTime += hours+':';
|
||||||
|
}
|
||||||
|
if (parseInt(minutes) > 0 || parseInt(hours) > 0) {
|
||||||
|
stringTime += minutes+':';
|
||||||
|
}
|
||||||
|
stringTime += seconds;
|
||||||
|
|
||||||
|
if (parseInt(stringTime) === 0) {
|
||||||
|
stringTime = 'N/A';
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatFromSeconds(seconds: number): string {
|
||||||
|
let stringTime = '';
|
||||||
|
let minutes = seconds / 60;
|
||||||
|
let hours = minutes / 60;
|
||||||
|
console.log(seconds, minutes, hours)
|
||||||
|
if (parseInt(hours) > 0) {
|
||||||
|
stringTime += (hours < 10) ? '0' : '';
|
||||||
|
stringTime += parseInt(hours) + ':';
|
||||||
|
seconds = seconds - (parseInt(hours) * 3600);
|
||||||
|
console.log(stringTime)
|
||||||
|
}
|
||||||
|
if (parseInt(hours) > 0 || parseInt(minutes) > 0) {
|
||||||
|
minutes = minutes - (parseInt(hours) * 60);
|
||||||
|
stringTime += (minutes < 10) ? '0' : '';
|
||||||
|
stringTime += parseInt(minutes) + ':';
|
||||||
|
seconds = seconds - (parseInt(minutes) * 60);
|
||||||
|
console.log(stringTime)
|
||||||
|
}
|
||||||
|
stringTime += seconds.toFixed(2);
|
||||||
|
console.log(stringTime)
|
||||||
|
return stringTime;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue