-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime.html
84 lines (73 loc) · 3.53 KB
/
time.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
<!-- SPDX-FileCopyrightText: orangc -->
<!DOCTYPE html>
<html lang="en" data-theme="rosepine">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="My timezone and current time.">
<meta property="og:title" content="orangc" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://orangc.net/" />
<meta property="og:image" content="https://orangc.net/leaf.png" />
<meta property="og:description" content="My timezone and current time." />
<meta name="theme-color" content="#fab387" />
<title>orangc</title>
<link rel="shortcut icon" href="leaf.ico" type="image/x-icon" />
<link rel="stylesheet" href="styles/output.css" />
</head>
<body class="justify-center items-center m-auto text-center">
<h1 class="font-extrabold mt-[40vh] select-none text-4xl"><span class="icon-[tabler--clock-filled] -mb-1"></span> <time id="myCurrentTime"></time></h1>
<p id="yourTimezone"></p>
<!-- Scripts -->
<script>
function updateCurrentTimeAndGreeting() {
const currentTimeElement = document.getElementById("myCurrentTime");
const timezoneElement = document.getElementById("yourTimezone");
if (currentTimeElement) {
const now = new Date();
const offset = 3; // UTC+3
const utc3 = new Date(now.getTime() + offset * 60 * 60 * 1000);
const formattedTime = utc3.toISOString().slice(11, 19); // HH:mm:ss format
currentTimeElement.innerHTML = `
${formattedTime} <span class="text-error">UTC+3</span>
`;
currentTimeElement.setAttribute("datetime", utc3.toISOString());
}
if (timezoneElement) {
const userOffsetMinutes = -new Date().getTimezoneOffset();
const userOffsetHours = userOffsetMinutes / 60;
const diffHours = userOffsetHours - 3; // Difference from UTC+3
const greeting = (() => {
const hours = new Date().getHours();
if (hours < 12) return "Good morning";
if (hours < 18) return "Good afternoon";
return "Good evening";
})();
if (diffHours === 0) {
timezoneElement.innerHTML = `
${greeting}, your timezone is the same as mine.
`;
} else {
const isAhead = diffHours > 0;
const direction = isAhead ? "ahead of" : "behind";
timezoneElement.innerHTML = `
${greeting}, your timezone is <span class="text-primary">UTC${userOffsetHours >= 0 ? '+' : ''}${userOffsetHours}</span>, which is <span class="text-error">${Math.abs(diffHours)}</span> hours ${direction} my timezone. <br> The above time is the current time in Riyadh, Saudi Arabia, where I live.
`;
}
}
}
updateCurrentTimeAndGreeting();
setInterval(updateCurrentTimeAndGreeting, 1000);
</script>
<script>
const savedTheme = localStorage.getItem("theme");
if (savedTheme) {
document.documentElement.setAttribute("data-theme", savedTheme);
if (savedTheme === "light") {
document.body.classList.add("font-serif");
}
}
</script>
</body>
</html>