36 lines
956 B
TypeScript
36 lines
956 B
TypeScript
import {prefix} from "../helpers";
|
|
|
|
export class Timestamp {
|
|
|
|
public readonly WEEKDAY: string[] = ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"];
|
|
|
|
public readonly dayName;
|
|
|
|
public readonly timeString;
|
|
|
|
public constructor(
|
|
readonly date: Date,
|
|
) {
|
|
const now = new Date();
|
|
const minutes: string = prefix(this.date.getMinutes(), '0', 2);
|
|
if (date.getDate() === now.getDate()) {
|
|
this.dayName = "Heute";
|
|
this.timeString = date.getHours() + ":" + minutes;
|
|
} else if (date.getDate() === now.getDate() + 1) {
|
|
this.dayName = "Morgen";
|
|
this.timeString = date.getHours() + ":" + minutes;
|
|
} else {
|
|
this.dayName = this.WEEKDAY[date.getDay()];
|
|
this.timeString = date.getHours() + ":" + minutes;
|
|
}
|
|
}
|
|
|
|
public static fromDateOrNull(date: Date | null): Timestamp | null {
|
|
if (date === null) {
|
|
return null;
|
|
}
|
|
return new Timestamp(date);
|
|
}
|
|
|
|
}
|