Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. export class Clock {
  2. constructor(
  3. hours = 0,
  4. minutes = 0
  5. ) {
  6. this.minutes = (hours * 60) + minutes;
  7. }
  8.  
  9. toString() {
  10. // return `${this.getHours().toString().padStart(2, '0')}:${this.getMinutes().toString().padStart(2, '0')}`;
  11. return `${this.getHours().toString()}:${this.getMinutes().toString()}`;
  12. }
  13.  
  14. getHours() {
  15.  
  16. return Math.floor(this.minutes/60) % 24;
  17. }
  18.  
  19. getMinutes() {
  20. return this.minutes % 60;
  21. }
  22.  
  23. plus(minutes) {
  24. this.minutes = this.minutes + minutes;
  25. return this;
  26. }
  27.  
  28. minus(minutes) {
  29. this.minutes = this.minutes - minutes;
  30. return this;
  31. }
  32.  
  33. equals(clock) {
  34. return this.toString() === clock.toString();
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement