Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class Clock {
- constructor(
- hours = 0,
- minutes = 0
- ) {
- this.minutes = (hours * 60) + minutes;
- }
- toString() {
- // return `${this.getHours().toString().padStart(2, '0')}:${this.getMinutes().toString().padStart(2, '0')}`;
- return `${this.getHours().toString()}:${this.getMinutes().toString()}`;
- }
- getHours() {
- return Math.floor(this.minutes/60) % 24;
- }
- getMinutes() {
- return this.minutes % 60;
- }
- plus(minutes) {
- this.minutes = this.minutes + minutes;
- return this;
- }
- minus(minutes) {
- this.minutes = this.minutes - minutes;
- return this;
- }
- equals(clock) {
- return this.toString() === clock.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement