Skip to content

Commit 94c806f

Browse files
authored
Add digital world clock feature with multi-timezone support (#4)
1 parent 5f0f13e commit 94c806f

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

examples/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/src/static/index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,35 @@
88
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
99
<link rel="icon" type="image/png" href="./playcanvas-logo.png" />
1010
<link rel="stylesheet" href="styles.css">
11+
<script src="https://cdn.tailwindcss.com"></script>
1112
</head>
1213
<body>
1314
<div id='app'></div>
15+
16+
<!-- World Clocks Section -->
17+
<div id="world-clocks" class="fixed bottom-4 right-4 bg-gray-900 bg-opacity-90 rounded-lg shadow-2xl p-6 backdrop-blur-sm border border-gray-700">
18+
<h2 class="text-2xl font-bold text-white mb-4 text-center border-b border-gray-700 pb-2">World Clocks</h2>
19+
<div class="grid grid-cols-2 gap-4">
20+
<div class="clock-item bg-gray-800 rounded-lg p-4 text-center hover:bg-gray-700 transition-colors">
21+
<div class="text-sm text-gray-400 mb-1">New York</div>
22+
<div id="clock-newyork" class="text-xl font-mono text-blue-400">--:--:--</div>
23+
</div>
24+
<div class="clock-item bg-gray-800 rounded-lg p-4 text-center hover:bg-gray-700 transition-colors">
25+
<div class="text-sm text-gray-400 mb-1">London</div>
26+
<div id="clock-london" class="text-xl font-mono text-green-400">--:--:--</div>
27+
</div>
28+
<div class="clock-item bg-gray-800 rounded-lg p-4 text-center hover:bg-gray-700 transition-colors">
29+
<div class="text-sm text-gray-400 mb-1">Tokyo</div>
30+
<div id="clock-tokyo" class="text-xl font-mono text-purple-400">--:--:--</div>
31+
</div>
32+
<div class="clock-item bg-gray-800 rounded-lg p-4 text-center hover:bg-gray-700 transition-colors">
33+
<div class="text-sm text-gray-400 mb-1">Local Time</div>
34+
<div id="clock-local" class="text-xl font-mono text-orange-400">--:--:--</div>
35+
</div>
36+
</div>
37+
</div>
38+
1439
<script src="index.js"></script>
40+
<script src="scripts/main.js"></script>
1541
</body>
1642
</html>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// World Clock Feature
2+
// Updates clocks for different time zones every second
3+
4+
/**
5+
* Updates all world clocks with current time
6+
*/
7+
function updateWorldClocks() {
8+
const now = new Date();
9+
10+
// Time zone configurations
11+
const timeZones = {
12+
'clock-newyork': 'America/New_York',
13+
'clock-london': 'Europe/London',
14+
'clock-tokyo': 'Asia/Tokyo',
15+
'clock-local': undefined // Local time zone
16+
};
17+
18+
// Update each clock
19+
Object.keys(timeZones).forEach((clockId) => {
20+
const element = document.getElementById(clockId);
21+
if (element) {
22+
const timeZone = timeZones[clockId];
23+
const options = {
24+
hour: '2-digit',
25+
minute: '2-digit',
26+
second: '2-digit',
27+
hour12: false,
28+
timeZone: timeZone
29+
};
30+
31+
try {
32+
const timeString = now.toLocaleTimeString('en-US', options);
33+
element.textContent = timeString;
34+
} catch (error) {
35+
console.error(`Error updating clock ${clockId}:`, error);
36+
element.textContent = 'Error';
37+
}
38+
}
39+
});
40+
}
41+
42+
// Initialize clocks when DOM is ready
43+
if (document.readyState === 'loading') {
44+
document.addEventListener('DOMContentLoaded', initializeClocks);
45+
} else {
46+
initializeClocks();
47+
}
48+
49+
function initializeClocks() {
50+
// Update clocks immediately
51+
updateWorldClocks();
52+
53+
// Update clocks every second
54+
setInterval(updateWorldClocks, 1000);
55+
}

0 commit comments

Comments
 (0)