From 5e4229e21051b2416ddacad345afa5b9f38b4442 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Mon, 6 Sep 2021 16:53:58 +0100 Subject: [PATCH] save --- .../group-messages/group-messages.page.ts | 9 ++-- .../services/functions/time.service.spec.ts | 16 +++++++ src/app/services/functions/time.service.ts | 47 +++++++++++++++++++ .../group-messages/group-messages.page.html | 2 +- .../group-messages/group-messages.page.ts | 7 ++- .../shared/chat/messages/messages.page.html | 2 +- src/app/shared/chat/messages/messages.page.ts | 8 +++- 7 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 src/app/services/functions/time.service.spec.ts create mode 100644 src/app/services/functions/time.service.ts 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 @@
{{msg.u.name}} - {{msg._updatedAt | date: 'HH:mm' }} + {{showDateDuration(msg._updatedAt)}}
{{msg.msg}} diff --git a/src/app/shared/chat/group-messages/group-messages.page.ts b/src/app/shared/chat/group-messages/group-messages.page.ts index 88f371032..a266277f4 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -10,6 +10,7 @@ import { GroupContactsPage } from './group-contacts/group-contacts.page'; import { Router } from '@angular/router' import { ChatOptionsPopoverPage } from '../../popover/chat-options-popover/chat-options-popover.page'; import { ChatOptionsFeaturesPage } from 'src/app/modals/chat-options-features/chat-options-features.page'; +import { TimeService } from 'src/app/services/functions/time.service'; @Component({ selector: 'app-group-messages', @@ -54,7 +55,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe private authService: AuthService, private animationController: AnimationController, private alertService: AlertService, - private route: Router + private route: Router, + private timeService: TimeService, ) { this.loggedUserChat = authService.ValidatedUserChat['data']; this.isGroupCreated = true; @@ -140,6 +142,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe console.log('here watching'); return this.roomId; } + showDateDuration(start:any){ + return this.timeService.showDateDuration(start); + } getRoomInfo(){ this.showLoader = true; diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 552158990..14bbc4c1a 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -35,7 +35,7 @@
{{msg.u.name}} - {{msg._updatedAt | date: 'HH:mm' }} + {{showDateDuration(msg._updatedAt)}}
{{msg.msg}} diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index b68c228c6..3e8bccfc4 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -12,6 +12,7 @@ import { synchro } from 'src/app/services/socket/synchro.service'; import { ChatOptionsFeaturesPage } from 'src/app/modals/chat-options-features/chat-options-features.page'; import { ChatMessageStore } from 'src/app/store/chat/chat-message.service'; import { ChatUserStorage } from 'src/app/store/chat/chat-user.service'; +import { TimeService } from 'src/app/services/functions/time.service'; @Component({ selector: 'app-messages', @@ -58,7 +59,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy private animationController: AnimationController, private alertService: AlertService, private toastService: ToastService, - private route: Router + private route: Router, + private timeService: TimeService, ) { this.loggedUser = authService.ValidatedUserChat['data']; @@ -151,6 +153,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.openNewEventPage.emit(data); } + showDateDuration(start:any){ + return this.timeService.showDateDuration(start); + } + sendMessage() { this.synchro.$send({})