Skip to content

Commit 65b5195

Browse files
committed
added timer
1 parent c34f9fa commit 65b5195

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h6 class="text-left"><strong>Totals</strong></h6>
2323
<div class="row">
2424
<div class="col-4">
2525
<h6>Current</h6>
26-
<h3>-</h3>
26+
<h3>{{ hour | number: '2.0-2' }}:{{ minute | number: '2.0-2' }}:{{ seconds | number: '2.0-2' }}</h3>
2727
</div>
2828
<div class="col-4">
2929
<h6>Day</h6>

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, OnDestroy } from '@angular/core';
2+
import { interval, timer } from 'rxjs';
3+
24

35
@Component({
46
selector: 'app-time-clock',
57
templateUrl: './time-clock.component.html',
68
styleUrls: ['./time-clock.component.css']
79
})
8-
export class TimeClockComponent {
10+
export class TimeClockComponent implements OnInit {
911

1012
username = 'Dario';
1113
clockInUsername = 'hh:mm:ss';
1214
clockOutUsername = 'hh:mm:ss';
13-
1415
isClockIn: boolean;
1516
isEnterTechnology: boolean;
1617
showAlertEnterTecnology: boolean;
1718

19+
hour: number;
20+
minute: number;
21+
seconds: number;
22+
23+
public timer;
24+
1825
constructor() {
1926
this.isClockIn = true;
2027
this.isEnterTechnology = false;
28+
this.hour = 0;
29+
this.minute = 0;
30+
this.seconds = 0;
2131
}
2232

2333
employeClockIn(): boolean {
2434
this.isClockIn = !this.isClockIn;
35+
this.enableTimer();
2536
return this.isClockIn;
2637
}
2738

@@ -33,6 +44,7 @@ export class TimeClockComponent {
3344
this.isClockIn = true;
3445
this.isEnterTechnology = false;
3546
this.showAlertEnterTecnology = false;
47+
console.log('Disble Timer');
3648
}
3749
}
3850

@@ -43,4 +55,27 @@ export class TimeClockComponent {
4355
this.isEnterTechnology = false;
4456
}
4557
}
58+
59+
enableTimer() {
60+
this.timer = interval(1000);
61+
this.timer.subscribe( (data) => {
62+
this.seconds += 1;
63+
if ( this.seconds === 59 ) {
64+
this.minute += 1;
65+
this.seconds = 0;
66+
if ( this.minute === 59 ) {
67+
this.hour += 1;
68+
this.minute = 0;
69+
}
70+
}
71+
// console.log(this.hour + ' : ' + this.minute + ' : ' + this.seconds);
72+
});
73+
74+
}
75+
76+
77+
ngOnInit(): void {
78+
}
79+
80+
4681
}

src/app/components/shared/clock/clock.component.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { interval, timer } from 'rxjs';
23

34
@Component({
45
selector: 'app-clock',
@@ -14,16 +15,23 @@ export class ClockComponent implements OnInit {
1415
displayTime: boolean;
1516

1617
constructor() {
17-
this.currentDate = new Date();
18-
this.hour = this.currentDate.getHours();
19-
this.minutes = this.currentDate.getMinutes();
20-
this.seconds = this.currentDate.getSeconds();
18+
this.showClcok();
2119
this.displayTime = false;
2220
setTimeout(() => {
2321
this.displayTime = true;
2422
}, 3000);
2523
}
2624

25+
showClcok() {
26+
const timer = interval(1000);
27+
timer.subscribe( (data) => {
28+
this.currentDate = new Date();
29+
this.hour = this.currentDate.getHours();
30+
this.minutes = this.currentDate.getMinutes();
31+
this.seconds = this.currentDate.getSeconds();
32+
} );
33+
}
34+
2735
ngOnInit(): void {
2836
}
2937

0 commit comments

Comments
 (0)