diff --git a/src/app/pages/chat/group-messages/group-messages.page.ts b/src/app/pages/chat/group-messages/group-messages.page.ts index ab82b2491..6ef11c520 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -10,6 +10,7 @@ import { NewGroupPage } from '../new-group/new-group.page'; import { GroupContactsPage } from './group-contacts/group-contacts.page'; import {Router} from '@angular/router' import { EditGroupPage } from '../edit-group/edit-group.page'; +import { TimeService } from 'src/app/services/functions/time.service'; @Component({ selector: 'app-group-messages', @@ -49,7 +50,8 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { private navParams: NavParams, private authService: AuthService, private alertService: AlertService, - private route: Router + private route: Router, + private timeService: TimeService, ) { this.loggedUserChat = authService.ValidatedUserChat['data']; this.isGroupCreated = true; @@ -178,7 +180,8 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } showDateDuration(start:any){ - let end; + return this.timeService.showDateDuration(start); + /* let end; end = new Date(); start = new Date(start); let customizedDate; @@ -204,7 +207,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { else{ let date = start.getDate() + "/" + (start.getMonth()+1) + "/" + start.getFullYear(); return date; - } + } */ } addZero(i) { diff --git a/src/app/services/functions/time.service.spec.ts b/src/app/services/functions/time.service.spec.ts new file mode 100644 index 000000000..c906c0a8f --- /dev/null +++ b/src/app/services/functions/time.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { TimeService } from './time.service'; + +describe('TimeService', () => { + let service: TimeService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(TimeService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/functions/time.service.ts b/src/app/services/functions/time.service.ts new file mode 100644 index 000000000..fa0bf2440 --- /dev/null +++ b/src/app/services/functions/time.service.ts @@ -0,0 +1,47 @@ +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{ + let date = start.getDate() + "/" + (start.getMonth()+1) + "/" + start.getFullYear(); + return date; + } + } + + addZero(i) { + if (i < 10) { + i = "0" + i; + } + return i; + } + +} diff --git a/src/app/shared/chat/group-messages/group-messages.page.html b/src/app/shared/chat/group-messages/group-messages.page.html index 3db44986d..db2c8cbe4 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -42,7 +42,7 @@