MCPcopy Create free account
hub / github.com/Everoot/everoot.github.io / ClockComponent

Class ClockComponent

src/app/components/clock/clock.ts:10–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8 styleUrl: './clock.css',
9})
10export class ClockComponent implements OnInit, OnDestroy {
11 private monthList = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
12 private dayList = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
13 private updateInterval: any;
14
15 currentTime = signal(new Date());
16 displayTime = signal('');
17
18 ngOnInit() {
19 this.updateTime();
20 this.updateInterval = setInterval(() => {
21 this.updateTime();
22 }, 10000); // Update every 10 seconds
23 }
24
25 ngOnDestroy() {
26 if (this.updateInterval) {
27 clearInterval(this.updateInterval);
28 }
29 }
30
31 updateTime() {
32 const now = new Date();
33 this.currentTime.set(now);
34
35 const day = this.dayList[now.getDay()];
36 let hour = now.getHours();
37 const minute = now.getMinutes().toString().padStart(2, '0');
38 const month = this.monthList[now.getMonth()];
39 const date = now.getDate();
40 const meridiem = hour < 12 ? 'AM' : 'PM';
41
42 if (hour > 12) hour -= 12;
43 if (hour === 0) hour = 12;
44
45 this.displayTime.set(`${day} ${month} ${date} ${hour}:${minute} ${meridiem}`);
46 }
47}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected