Skip to content

Commit ba7f7d5

Browse files
committed
timer working
Clock component
1 parent 693c8f5 commit ba7f7d5

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/app/components/options-sidebar/time-clock/time-clock.component.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ export class TimeClockComponent implements OnInit {
2121
isClockIn: boolean;
2222
isEnterTechnology: boolean;
2323
showAlertEnterTecnology: boolean;
24-
24+
showFields: boolean;
2525
hour: number;
2626
minute: number;
2727
seconds: number;
28-
29-
showFields: boolean;
28+
interval;
3029

3130
constructor() {
3231
this.isClockIn = true;
@@ -38,6 +37,7 @@ export class TimeClockComponent implements OnInit {
3837

3938
employeClockIn(): boolean {
4039
this.isClockIn = !this.isClockIn;
40+
this.startTimer();
4141
return this.isClockIn;
4242
}
4343

@@ -49,6 +49,7 @@ export class TimeClockComponent implements OnInit {
4949
this.isClockIn = true;
5050
this.isEnterTechnology = false;
5151
this.showAlertEnterTecnology = false;
52+
this.pauseTimer();
5253
}
5354
}
5455

@@ -65,6 +66,28 @@ export class TimeClockComponent implements OnInit {
6566
this.showFields = show;
6667
}
6768

69+
startTimer() {
70+
this.interval = setInterval(() => {
71+
this.timer();
72+
}, 1000 );
73+
}
74+
75+
pauseTimer() {
76+
clearInterval(this.interval);
77+
}
78+
79+
timer() {
80+
this.seconds += 1;
81+
if ( this.seconds === 59 ) {
82+
this.minute += 1;
83+
this.seconds = 0;
84+
if ( this.minute === 59 ) {
85+
this.hour += 1;
86+
this.minute = 0;
87+
}
88+
}
89+
}
90+
6891
ngOnInit(): void {}
6992

7093
}

0 commit comments

Comments
 (0)