format message time in timeFormatter as well

This commit is contained in:
Bruno Windels 2022-11-25 16:47:54 +01:00
parent 85a06876cd
commit 77fd7e7aca
3 changed files with 9 additions and 1 deletions

View File

@ -84,7 +84,7 @@ export class BaseMessageTile extends SimpleTile {
} }
get time() { get time() {
return this._date && this._date.toLocaleTimeString({}, {hour: "numeric", minute: "2-digit"}); return this._date && this.timeFormatter.formatTime(this._date);
} }
get isOwn() { get isOwn() {

View File

@ -45,6 +45,7 @@ export type File = {
} }
export interface ITimeFormatter { export interface ITimeFormatter {
formatTime(date: Date): string;
formatRelativeDate(date: Date): string; formatRelativeDate(date: Date): string;
formatMachineReadableDate(date: Date): string; formatMachineReadableDate(date: Date): string;
} }

View File

@ -29,6 +29,7 @@ export class TimeFormatter implements ITimeFormatter {
private weekdayFormatter: Intl.DateTimeFormat; private weekdayFormatter: Intl.DateTimeFormat;
private currentYearFormatter: Intl.DateTimeFormat; private currentYearFormatter: Intl.DateTimeFormat;
private otherYearFormatter: Intl.DateTimeFormat; private otherYearFormatter: Intl.DateTimeFormat;
private timeFormatter: Intl.DateTimeFormat;
constructor(private clock: Clock) { constructor(private clock: Clock) {
// don't use the clock time here as the DOM relative formatters don't support setting the reference date anyway // 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', month: 'long',
day: 'numeric' 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 { formatMachineReadableDate(date: Date): string {
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
} }