File tree Expand file tree Collapse file tree 5 files changed +36
-9
lines changed Expand file tree Collapse file tree 5 files changed +36
-9
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ <h6 class="text-left"><strong>Totals</strong></h6>
2424 < div class ="row ">
2525 < div class ="col-4 ">
2626 < h6 > Current</ h6 >
27- < h3 > - </ h3 >
27+ < h3 > {{ hour | number: '2.0-2' }}:{{ minute | number: '2.0-2' }}:{{ seconds | number: '2.0-2' }} </ h3 >
2828 </ div >
2929 < div class ="col-4 ">
3030 < h6 > Day</ h6 >
Original file line number Diff line number Diff line change 11import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
22import { By } from '@angular/platform-browser' ;
33import { DebugElement } from '@angular/core' ;
4-
54import { TimeClockComponent } from './time-clock.component' ;
65import { ProjectListHoverComponent } from '../../shared/project-list-hover/project-list-hover.component' ;
76
@@ -41,7 +40,6 @@ describe('TimeClockComponent', () => {
4140 const compile = fixture . debugElement . nativeElement ;
4241 const ptag = compile . querySelector ( 'p' ) ;
4342 expect ( ptag . textContent ) . toBe ( 'Dario clocked out at hh:mm:ss' ) ;
44-
4543 } ) ) ;
4644
4745 it ( 'should set showfileds as true' , ( ) => {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { Component, OnInit } from '@angular/core';
55 templateUrl : './time-clock.component.html' ,
66 styleUrls : [ './time-clock.component.css' ]
77} )
8+
89export class TimeClockComponent implements OnInit {
910
1011 projects = [
@@ -17,15 +18,22 @@ export class TimeClockComponent implements OnInit {
1718 username = 'Dario' ;
1819 clockInUsername = 'hh:mm:ss' ;
1920 clockOutUsername = 'hh:mm:ss' ;
20-
2121 isClockIn : boolean ;
2222 isEnterTechnology : boolean ;
2323 showAlertEnterTecnology : boolean ;
24+
25+ hour : number ;
26+ minute : number ;
27+ seconds : number ;
28+
2429 showFields : boolean ;
2530
2631 constructor ( ) {
2732 this . isClockIn = true ;
2833 this . isEnterTechnology = false ;
34+ this . hour = 0 ;
35+ this . minute = 0 ;
36+ this . seconds = 0 ;
2937 }
3038
3139 employeClockIn ( ) : boolean {
@@ -58,4 +66,5 @@ export class TimeClockComponent implements OnInit {
5866 }
5967
6068 ngOnInit ( ) : void { }
69+
6170}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ describe('ClockComponent', () => {
66 let component : ClockComponent ;
77 let fixture : ComponentFixture < ClockComponent > ;
88
9+
910 beforeEach ( async ( ( ) => {
1011 TestBed . configureTestingModule ( {
1112 declarations : [ ClockComponent ]
@@ -22,4 +23,15 @@ describe('ClockComponent', () => {
2223 it ( 'should create' , ( ) => {
2324 expect ( component ) . toBeTruthy ( ) ;
2425 } ) ;
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+
2537} ) ;
Original file line number Diff line number Diff line change 11import { Component , OnInit } from '@angular/core' ;
2+ import { interval , timer } from 'rxjs' ;
23
34@Component ( {
45 selector : 'app-clock' ,
@@ -7,23 +8,30 @@ import { Component, OnInit } from '@angular/core';
78} )
89export class ClockComponent implements OnInit {
910
10- currentDate : Date ;
11+ currentDate : Date = new Date ( ) ;
1112 hour : number ;
1213 minutes : number ;
1314 seconds : number ;
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 timenInterval = interval ( 1000 ) ;
27+ timenInterval . 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
You can’t perform that action at this time.
0 commit comments