File tree Expand file tree Collapse file tree 3 files changed +16
-30
lines changed Expand file tree Collapse file tree 3 files changed +16
-30
lines changed Original file line number Diff line number Diff line change 1
1
import { Component , OnInit , OnDestroy } from '@angular/core' ;
2
- import { interval , timer } from 'rxjs' ;
3
-
4
2
5
3
@Component ( {
6
4
selector : 'app-time-clock' ,
@@ -15,13 +13,10 @@ export class TimeClockComponent implements OnInit {
15
13
isClockIn : boolean ;
16
14
isEnterTechnology : boolean ;
17
15
showAlertEnterTecnology : boolean ;
18
-
19
16
hour : number ;
20
17
minute : number ;
21
18
seconds : number ;
22
19
23
- public timer ;
24
-
25
20
constructor ( ) {
26
21
this . isClockIn = true ;
27
22
this . isEnterTechnology = false ;
@@ -32,7 +27,6 @@ export class TimeClockComponent implements OnInit {
32
27
33
28
employeClockIn ( ) : boolean {
34
29
this . isClockIn = ! this . isClockIn ;
35
- this . enableTimer ( ) ;
36
30
return this . isClockIn ;
37
31
}
38
32
@@ -44,7 +38,6 @@ export class TimeClockComponent implements OnInit {
44
38
this . isClockIn = true ;
45
39
this . isEnterTechnology = false ;
46
40
this . showAlertEnterTecnology = false ;
47
- console . log ( 'Disble Timer' ) ;
48
41
}
49
42
}
50
43
@@ -56,26 +49,7 @@ export class TimeClockComponent implements OnInit {
56
49
}
57
50
}
58
51
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
52
ngOnInit ( ) : void {
78
53
}
79
54
80
-
81
55
}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ describe('ClockComponent', () => {
6
6
let component : ClockComponent ;
7
7
let fixture : ComponentFixture < ClockComponent > ;
8
8
9
+
9
10
beforeEach ( async ( ( ) => {
10
11
TestBed . configureTestingModule ( {
11
12
declarations : [ ClockComponent ]
@@ -22,4 +23,15 @@ describe('ClockComponent', () => {
22
23
it ( 'should create' , ( ) => {
23
24
expect ( component ) . toBeTruthy ( ) ;
24
25
} ) ;
26
+
27
+ it ( 'should show the current hour of day' , ( ) => {
28
+ const currentHour = 11 ;
29
+ expect ( component . currentDate . getHours ( ) ) . toEqual ( currentHour ) ;
30
+ } ) ;
31
+
32
+ it ( 'should show the current minutes of day' , ( ) => {
33
+ const currenMinutes = 5 ;
34
+ expect ( component . currentDate . getMinutes ( ) ) . toEqual ( currenMinutes ) ;
35
+ } ) ;
36
+
25
37
} ) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { interval, timer } from 'rxjs';
8
8
} )
9
9
export class ClockComponent implements OnInit {
10
10
11
- currentDate : Date ;
11
+ currentDate : Date = new Date ( ) ;
12
12
hour : number ;
13
13
minutes : number ;
14
14
seconds : number ;
@@ -23,13 +23,13 @@ export class ClockComponent implements OnInit {
23
23
}
24
24
25
25
showClcok ( ) {
26
- const timer = interval ( 1000 ) ;
27
- timer . subscribe ( ( data ) => {
26
+ const timenInterval = interval ( 1000 ) ;
27
+ timenInterval . subscribe ( ( data ) => {
28
28
this . currentDate = new Date ( ) ;
29
29
this . hour = this . currentDate . getHours ( ) ;
30
30
this . minutes = this . currentDate . getMinutes ( ) ;
31
31
this . seconds = this . currentDate . getSeconds ( ) ;
32
- } ) ;
32
+ } ) ;
33
33
}
34
34
35
35
ngOnInit ( ) : void {
You can’t perform that action at this time.
0 commit comments