-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.ts
More file actions
62 lines (55 loc) · 1.43 KB
/
mod.ts
File metadata and controls
62 lines (55 loc) · 1.43 KB
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
import { Hono } from "jsr:@hono/hono";
const now = new Date();
const dayOfYear = Math.floor(
(now.getTime() - new Date(now.getFullYear(), 0, 0).getTime()) /
(1000 * 60 * 60 * 24),
);
const progress = (dayOfYear / 365) * 100;
const daysInYear =
(now.getFullYear() % 4 === 0 && now.getFullYear() % 100 !== 0) ||
now.getFullYear() % 400 === 0
? 366
: 365;
const app = new Hono();
const routes = {
"/": {
progress: progress.toFixed(2) + "%",
day: dayOfYear,
remaining: {
percentage: (100 - progress).toFixed(2) + "%",
daysLeft: daysInYear - dayOfYear,
},
year: now.getFullYear(),
currentDateTime: now.toISOString(),
},
"/days": {
message: "Current day of the year",
dayOfYear,
},
"/percentage": {
message: "Year progress percentage",
percentage: progress.toFixed(2) + "%",
},
"/remaining": {
message: "Remaining percentage of the year",
remaining: (100 - progress).toFixed(2) + "%",
},
"/decimal": {
message: "Year progress in decimal",
decimal: (dayOfYear / 365).toFixed(2),
},
"/remaining/days": {
message: "Days remaining in the year",
remaining: daysInYear - dayOfYear,
},
"/time": {
message: "Current server time",
time: now.toISOString(),
},
};
Object.entries(routes).forEach(([path, data]) =>
app.get(path, (c) => c.json(data))
);
app.notFound((c) => c.text("Not Found", 404));
Deno.serve(app.fetch);
export { app };