2021-09-06 16:53:58 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2021-10-27 08:45:37 +01:00
|
|
|
import { ChatService } from '../chat.service';
|
2022-09-30 15:13:36 +01:00
|
|
|
import { ChatSystemService } from '../chat/chat-system.service';
|
2021-09-06 16:53:58 +01:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class TimeService {
|
2021-10-27 08:45:37 +01:00
|
|
|
countDownTime: any;
|
|
|
|
|
room: any;
|
2021-09-06 16:53:58 +01:00
|
|
|
|
2022-06-08 16:09:40 +01:00
|
|
|
constructor(private chatService: ChatService,
|
2022-09-30 15:13:36 +01:00
|
|
|
public ChatSystemService: ChatSystemService,) { }
|
2021-09-06 16:53:58 +01:00
|
|
|
|
2022-06-08 16:09:40 +01:00
|
|
|
showDateDuration(start:any) {
|
2021-09-06 16:53:58 +01:00
|
|
|
let end;
|
|
|
|
|
end = new Date();
|
|
|
|
|
start = new Date(start);
|
2021-10-27 08:45:37 +01:00
|
|
|
|
2022-12-19 17:04:21 +01:00
|
|
|
const totalSeconds = Math.floor((end - (start))/1000);
|
2021-09-06 16:53:58 +01:00
|
|
|
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 );
|
|
|
|
|
|
2022-06-08 16:09:40 +01:00
|
|
|
if(totalDays == 0) {
|
|
|
|
|
if(start.getDate() == new Date().getDate()) {
|
2021-09-06 16:53:58 +01:00
|
|
|
let time = start.getHours() + ":" + this.addZero(start.getUTCMinutes());
|
|
|
|
|
return time;
|
|
|
|
|
}
|
2022-06-08 16:09:40 +01:00
|
|
|
else {
|
2021-09-06 16:53:58 +01:00
|
|
|
return 'Ontem';
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-08 16:09:40 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-27 08:45:37 +01:00
|
|
|
countDownDate(date:any, roomId:string){
|
2022-06-08 16:09:40 +01:00
|
|
|
|
|
|
|
|
let difference = new Date(date).getTime() - new Date().getTime();
|
|
|
|
|
let c_day = Math.floor(difference/(1000*60*60*24));
|
|
|
|
|
let c_hours = Math.floor((difference % (1000*60*60*24)) / (1000*60*60));
|
|
|
|
|
let c_minutes = Math.floor((difference % (1000*60*60)) / (1000*60));
|
|
|
|
|
let c_seconds = Math.floor((difference % (1000*60)) / 1000);
|
|
|
|
|
|
|
|
|
|
this.countDownTime = this.addZero(c_day) + " : " + this.addZero(c_hours) + " : " + this.addZero(c_minutes) + " : " + this.addZero(c_seconds) ;
|
|
|
|
|
|
|
|
|
|
if(difference < 0){
|
|
|
|
|
|
|
|
|
|
this.countDownTime = "Expired";
|
|
|
|
|
let body = { "roomId":roomId, }
|
|
|
|
|
this.chatService.getRoomInfo(roomId).subscribe(room=>{
|
|
|
|
|
this.room = room['room'];
|
|
|
|
|
|
|
|
|
|
if(this.room.t === 'p'){
|
|
|
|
|
this.chatService.deleteGroup(body).subscribe(res=>{
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
this.chatService.deleteChannel(body).subscribe(res=>{
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-27 08:45:37 +01:00
|
|
|
return this.countDownTime;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 15:35:01 +01:00
|
|
|
countDownDateTimer(date:any, roomId:string){
|
2022-12-19 17:04:21 +01:00
|
|
|
// let timer = setInterval(() =>{
|
|
|
|
|
// let difference = new Date(date).getTime() - new Date().getTime();
|
|
|
|
|
// let c_day = Math.floor(difference/(1000*60*60*24));
|
|
|
|
|
// let c_hours = Math.floor((difference % (1000*60*60*24)) / (1000*60*60));
|
|
|
|
|
// let c_minutes = Math.floor((difference % (1000*60*60)) / (1000*60));
|
|
|
|
|
// let c_seconds = Math.floor((difference % (1000*60)) / 1000);
|
|
|
|
|
|
|
|
|
|
// this.countDownTime = this.addZero(c_day) + " : " + this.addZero(c_hours) + " : " + this.addZero(c_minutes) + " : " + this.addZero(c_seconds) ;
|
|
|
|
|
|
|
|
|
|
// if(difference < 0) {
|
|
|
|
|
// clearInterval(timer);
|
|
|
|
|
// this.countDownTime = "Expired";
|
|
|
|
|
// let body = { "roomId":roomId, }
|
|
|
|
|
// this.chatService.getRoomInfo(roomId).subscribe(room=>{
|
|
|
|
|
// this.room = room['room'];
|
|
|
|
|
|
|
|
|
|
// if(this.room.t === 'p'){
|
|
|
|
|
// this.chatService.deleteGroup(body).subscribe(res=>{
|
|
|
|
|
// this.ChatSystemService.deleteRoom(roomId)
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// else{
|
2022-06-08 16:09:40 +01:00
|
|
|
|
2022-12-19 17:04:21 +01:00
|
|
|
// this.chatService.deleteChannel(body).subscribe(res=>{
|
|
|
|
|
// this.ChatSystemService.deleteRoom(roomId)
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// return this.countDownTime;
|
2021-11-03 15:35:01 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-06 16:53:58 +01:00
|
|
|
addZero(i) {
|
|
|
|
|
if (i < 10) {
|
|
|
|
|
i = "0" + i;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|