From 2d3457cf6fa872fe277dcff3a43b93d8be5353a7 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Tue, 27 Apr 2021 10:48:29 +0200 Subject: [PATCH] key created_at for comment, format date --- src/app/core/models/comment.model.ts | 4 +--- .../shared/components/comments/comments.component.html | 8 +++++--- .../shared/components/comments/comments.component.scss | 3 +++ src/app/shared/components/comments/comments.component.ts | 1 + 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app/core/models/comment.model.ts b/src/app/core/models/comment.model.ts index 0cce1157..8b9f939b 100644 --- a/src/app/core/models/comment.model.ts +++ b/src/app/core/models/comment.model.ts @@ -1,7 +1,5 @@ -import { User } from './user.model'; - export class Comment { - constructor(public text: string, public pseudo: string, public created_at: string) {} + constructor(public id: string, public text: string, public pseudo: string, public created_at: string) {} public static sortChronologically(first: Comment, second: Comment): number { const a = new Date(first.created_at); diff --git a/src/app/shared/components/comments/comments.component.html b/src/app/shared/components/comments/comments.component.html index 22bd3962..f3ca856e 100644 --- a/src/app/shared/components/comments/comments.component.html +++ b/src/app/shared/components/comments/comments.component.html @@ -67,10 +67,12 @@

{{ comment.pseudo }} , - + il y a - {{ calculateDaysAgoOfComment(comment.date.date) }} jours, le {{ comment.date.date }} + {{ calculateDaysAgoOfComment(comment.created_at) }} jours, le + {{ comment.created_at | date: 'short':'Europe/Paris':'fr_FR' }} +

diff --git a/src/app/shared/components/comments/comments.component.scss b/src/app/shared/components/comments/comments.component.scss index e69de29b..7cfdd368 100644 --- a/src/app/shared/components/comments/comments.component.scss +++ b/src/app/shared/components/comments/comments.component.scss @@ -0,0 +1,3 @@ +.date { + font-size: 0.85em; +} diff --git a/src/app/shared/components/comments/comments.component.ts b/src/app/shared/components/comments/comments.component.ts index 7de1c384..086fef07 100644 --- a/src/app/shared/components/comments/comments.component.ts +++ b/src/app/shared/components/comments/comments.component.ts @@ -17,6 +17,7 @@ export class CommentsComponent { }; constructor(private pollService: PollService) {} + calculateDaysAgoOfComment(dateAsString) { let numberOfDays = 0;