Skip to content

Commit 693c8f5

Browse files
authored
Merge pull request #17 from ioet/Clock-Component
Clock component
2 parents a5e15ee + 861434a commit 693c8f5

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
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
@@ -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>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22
import { By } from '@angular/platform-browser';
33
import { DebugElement } from '@angular/core';
4-
54
import { TimeClockComponent } from './time-clock.component';
65
import { 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', () => {

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
89
export 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
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

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

Lines changed: 13 additions & 5 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',
@@ -7,23 +8,30 @@ import { Component, OnInit } from '@angular/core';
78
})
89
export 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

0 commit comments

Comments
 (0)