From 00944e80fa14df055943c5964ff4f0f19b1993d3 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Fri, 14 Jun 2024 20:53:22 +0200 Subject: [PATCH] improved date and translation handling --- .../single-chat/single-chat.component.ts | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/app/components/main-chat/single-chat/single-chat.component.ts b/src/app/components/main-chat/single-chat/single-chat.component.ts index 8ec311b..b5833cc 100644 --- a/src/app/components/main-chat/single-chat/single-chat.component.ts +++ b/src/app/components/main-chat/single-chat/single-chat.component.ts @@ -15,7 +15,7 @@ import { PickerComponent } from '@ctrl/ngx-emoji-mart'; import { EditMsgComponent } from './edit-msg/edit-msg.component'; import { ReactionEmojisComponent } from './reaction-emojis/reaction-emojis.component'; import { UserService } from '../../../service/user.service'; -import { TranslateModule } from '@ngx-translate/core'; +import { TranslateModule, TranslateService } from '@ngx-translate/core'; @Component({ selector: 'app-single-chat', @@ -60,7 +60,8 @@ export class SingleChatComponent { public chatService: ChatService, public channelService: ChatService, public userService: UserService, - public downloadFilesService: DownloadFilesService + public downloadFilesService: DownloadFilesService, + private translateService: TranslateService ) {} /** @@ -143,29 +144,19 @@ export class SingleChatComponent { * @param {number} timestamp - The timestamp to convert. * @returns {string} The formatted date string. */ - convertTimestampDate(timestamp: number) { + convertTimestampDate(timestamp: number): string { const currentDate = new Date(); const inputDate = new Date(timestamp * 1000); - const months = [ - 'Jan.', - 'Feb.', - 'Mar.', - 'Apr.', - 'May.', - 'Jun.', - 'Jul.', - 'Aug.', - 'Sep.', - 'Oct.', - 'Nov.', - 'Dec.', - ]; const dayNumber = inputDate.getDate(); - const month = months[inputDate.getMonth()]; + const month = this.translateService.instant( + `months.${inputDate + .toLocaleDateString('en-US', { month: 'short' }) + .toLowerCase()}` + ); if (inputDate.toDateString() === currentDate.toDateString()) { - return `Today`; + return this.translateService.instant('months.today'); } else { return `${dayNumber} ${month}`; }