[fabric/core] Add ClockTime class
This commit is contained in:
parent
c38f74414b
commit
53a7b31bdc
23
packages/fabric/core/time/clock-time.ts
Normal file
23
packages/fabric/core/time/clock-time.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,2 +1,3 @@
|
|||||||
|
export * from "./clock-time.ts";
|
||||||
export * from "./posix-date.ts";
|
export * from "./posix-date.ts";
|
||||||
export * from "./time-constants.ts";
|
export * from "./time-constants.ts";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user