2021-09-06 16:53:58 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class TimeService {
|
|
|
|
|
|
|
|
|
|
constructor() { }
|
|
|
|
|
|
|
|
|
|
showDateDuration(start:any){
|
|
|
|
|
let end;
|
|
|
|
|
end = new Date();
|
|
|
|
|
start = new Date(start);
|
|
|
|
|
let customizedDate;
|
|
|
|
|
|
|
|
|
|
const totalSeconds = Math.floor((end - (start))/1000);;
|
|
|
|
|
const totalMinutes = Math.floor(totalSeconds/60);
|
|
|
|
|
const totalHours = Math.floor(totalMinutes/60);
|
|
|
|
|
const totalDays = Math.floor(totalHours/24);
|
|
|
|
|
|
|
|
|
|
const hours = totalHours - ( totalDays * 24 );
|
|
|
|
|
const minutes = totalMinutes - ( totalDays * 24 * 60 ) - ( hours * 60 );
|
|
|
|
|
const seconds = totalSeconds - ( totalDays * 24 * 60 * 60 ) - ( hours * 60 * 60 ) - ( minutes * 60 );
|
|
|
|
|
|
|
|
|
|
if(totalDays == 0){
|
|
|
|
|
if(start.getDate() == new Date().getDate()){
|
|
|
|
|
let time = start.getHours() + ":" + this.addZero(start.getUTCMinutes());
|
|
|
|
|
return time;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
return 'Ontem';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
2021-09-06 16:57:25 +01:00
|
|
|
let date = this.addZero(start.getDate()) + "/" + this.addZero(start.getMonth()+1) + "/" + start.getFullYear();
|
2021-09-06 16:53:58 +01:00
|
|
|
return date;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addZero(i) {
|
|
|
|
|
if (i < 10) {
|
|
|
|
|
i = "0" + i;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|