mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-01-22 18:21:39 +01:00
format message time in timeFormatter as well
This commit is contained in:
parent
85a06876cd
commit
77fd7e7aca
@ -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() {
|
||||||
|
@ -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;
|
||||||
}
|
}
|
@ -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()}`;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user