Skip to content

Commit f2dbf42

Browse files
committed
added time to entry and out
1 parent ba7f7d5 commit f2dbf42

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
</div>
1818

1919
<div class="card-body">
20-
<p *ngIf="!isClockIn" class="card-title text-left"><strong>{{ username }}</strong> clocked <strong class="text-success">in</strong> at <strong>{{ clockInUsername }}</strong></p>
21-
<p *ngIf="isClockIn" class="card-title text-left"><strong>{{ username }}</strong> clocked <strong class="text-danger">out</strong> at <strong>{{ clockOutUsername }}</strong></p>
20+
<p *ngIf="!isClockIn" class="card-title text-left"><strong>{{ username }}</strong> clocked <strong class="text-success">in</strong> at <strong>{{ hour | number: '2.0-2' }}:{{ minute | number: '2.0-2' }}:{{ seconds | number: '2.0-2' }}</strong></p>
21+
<p *ngIf="isClockIn" class="card-title text-left"><strong>{{ username }}</strong> clocked <strong class="text-danger">out</strong> at <strong>{{ hour | number: '2.0-2' }}:{{ minute | number: '2.0-2' }}:{{ seconds | number: '2.0-2' }}</strong></p>
2222
<h6 class="text-left"><strong>Totals</strong></h6>
2323
<hr>
2424
<div class="row">
2525
<div class="col-4">
2626
<h6>Current</h6>
27-
<h3>{{ hour | number: '2.0-2' }}:{{ minute | number: '2.0-2' }}:{{ seconds | number: '2.0-2' }}</h3>
27+
<h3>{{ hourCounterRealTime | number: '2.0-2' }}:{{ minuteCounterRealTime | number: '2.0-2' }}:{{ secondsCounterRealTime | number: '2.0-2' }}</h3>
2828
</div>
2929
<div class="col-4">
3030
<h6>Day</h6>

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ export class TimeClockComponent implements OnInit {
1515
{ id: 'P4', name: 'Project 4' }
1616
];
1717

18+
currentDate: Date = new Date();
1819
username = 'Dario';
19-
clockInUsername = 'hh:mm:ss';
20-
clockOutUsername = 'hh:mm:ss';
2120
isClockIn: boolean;
2221
isEnterTechnology: boolean;
2322
showAlertEnterTecnology: boolean;
2423
showFields: boolean;
24+
hourCounterRealTime: number;
25+
minuteCounterRealTime: number;
26+
secondsCounterRealTime: number;
2527
hour: number;
2628
minute: number;
2729
seconds: number;
@@ -30,6 +32,9 @@ export class TimeClockComponent implements OnInit {
3032
constructor() {
3133
this.isClockIn = true;
3234
this.isEnterTechnology = false;
35+
this.hourCounterRealTime = 0;
36+
this.minuteCounterRealTime = 0;
37+
this.secondsCounterRealTime = 0;
3338
this.hour = 0;
3439
this.minute = 0;
3540
this.seconds = 0;
@@ -38,6 +43,7 @@ export class TimeClockComponent implements OnInit {
3843
employeClockIn(): boolean {
3944
this.isClockIn = !this.isClockIn;
4045
this.startTimer();
46+
this.setTimeToInOut();
4147
return this.isClockIn;
4248
}
4349

@@ -50,6 +56,7 @@ export class TimeClockComponent implements OnInit {
5056
this.isEnterTechnology = false;
5157
this.showAlertEnterTecnology = false;
5258
this.pauseTimer();
59+
this.setTimeToInOut();
5360
}
5461
}
5562

@@ -73,21 +80,28 @@ export class TimeClockComponent implements OnInit {
7380
}
7481

7582
pauseTimer() {
76-
clearInterval(this.interval);
83+
clearInterval(this.interval);
7784
}
7885

7986
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+
this.secondsCounterRealTime += 1;
88+
if ( this.secondsCounterRealTime === 59 ) {
89+
this.minuteCounterRealTime += 1;
90+
this.secondsCounterRealTime = 0;
91+
if ( this.minuteCounterRealTime === 59 ) {
92+
this.hourCounterRealTime += 1;
93+
this.minuteCounterRealTime = 0;
8794
}
8895
}
8996
}
9097

98+
setTimeToInOut(){
99+
this.currentDate = new Date();
100+
this.hour = this.currentDate.getHours();
101+
this.minute = this.currentDate.getMinutes();
102+
this.seconds = this.currentDate.getSeconds();
103+
}
104+
91105
ngOnInit(): void {}
92106

93107
}

0 commit comments

Comments
 (0)