From 77fd7e7aca680282a1d7ec64da189f0074f9431a Mon Sep 17 00:00:00 2001 From: Bruno Windels <274386+bwindels@users.noreply.github.com> Date: Fri, 25 Nov 2022 16:47:54 +0100 Subject: [PATCH] format message time in timeFormatter as well --- src/domain/session/room/timeline/tiles/BaseMessageTile.js | 2 +- src/platform/types/types.ts | 1 + src/platform/web/dom/TimeFormatter.ts | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/domain/session/room/timeline/tiles/BaseMessageTile.js b/src/domain/session/room/timeline/tiles/BaseMessageTile.js index 1ad1ba44..05ff1867 100644 --- a/src/domain/session/room/timeline/tiles/BaseMessageTile.js +++ b/src/domain/session/room/timeline/tiles/BaseMessageTile.js @@ -84,7 +84,7 @@ export class BaseMessageTile extends SimpleTile { } get time() { - return this._date && this._date.toLocaleTimeString({}, {hour: "numeric", minute: "2-digit"}); + return this._date && this.timeFormatter.formatTime(this._date); } get isOwn() { diff --git a/src/platform/types/types.ts b/src/platform/types/types.ts index 9147f6b8..df7ce6ac 100644 --- a/src/platform/types/types.ts +++ b/src/platform/types/types.ts @@ -45,6 +45,7 @@ export type File = { } export interface ITimeFormatter { + formatTime(date: Date): string; formatRelativeDate(date: Date): string; formatMachineReadableDate(date: Date): string; } \ No newline at end of file diff --git a/src/platform/web/dom/TimeFormatter.ts b/src/platform/web/dom/TimeFormatter.ts index 3f354713..7db879ea 100644 --- a/src/platform/web/dom/TimeFormatter.ts +++ b/src/platform/web/dom/TimeFormatter.ts @@ -29,6 +29,7 @@ export class TimeFormatter implements ITimeFormatter { private weekdayFormatter: Intl.DateTimeFormat; private currentYearFormatter: Intl.DateTimeFormat; private otherYearFormatter: Intl.DateTimeFormat; + private timeFormatter: Intl.DateTimeFormat; constructor(private clock: Clock) { // don't use the clock time here as the DOM relative formatters don't support setting the reference date anyway @@ -47,7 +48,13 @@ export class TimeFormatter implements ITimeFormatter { month: 'long', day: 'numeric' }); + this.timeFormatter = new Intl.DateTimeFormat(undefined, {hour: "numeric", minute: "2-digit"}); } + + formatTime(date: Date): string { + return this.timeFormatter.format(date); + } + formatMachineReadableDate(date: Date): string { return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; }