[fabric/core] Add ClockTime class

This commit is contained in:
Pablo Baleztena 2024-10-20 11:29:51 -03:00
parent c38f74414b
commit 53a7b31bdc
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,23 @@
/**
* Represents a time of day in hours, minutes, and seconds.
*/
export class ClockTime {
readonly hours: number;
readonly minutes: number;
readonly seconds: number;
constructor(hours?: number, minutes?: number, seconds?: number) {
this.hours = hours ?? 0;
this.minutes = minutes ?? 0;
this.seconds = seconds ?? 0;
}
toString() {
return `${this.hours}:${this.minutes}:${this.seconds}`;
}
static fromString(time: string): ClockTime {
const [hours, minutes, seconds] = time.split(":").map(Number);
return new ClockTime(hours, minutes, seconds);
}
}

View File

@ -1,2 +1,3 @@
export * from "./clock-time.ts";
export * from "./posix-date.ts";
export * from "./time-constants.ts";