-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathages_progress.html
More file actions
158 lines (127 loc) · 4.34 KB
/
ages_progress.html
File metadata and controls
158 lines (127 loc) · 4.34 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
<title>Time Progress</title>
<style>
body {
background: #000;
color: #fff;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
padding: 0.0vw;
}
.row {
display: flex;
align-items: center;
margin-bottom: 1.4vw;
}
.label {
width: 14.0vw;
font-size: 2.8vw;
white-space: nowrap;
}
.bar-container {
flex: 1;
height: 3.4vw;
border: 0.2vw solid #fff;
margin: 2.0vw;
position: relative;
}
.bar {
height: 100%;
background: #fff;
width: 0%;
}
.percent {
width: 8.0vw;
font-size: 2.8vw;
text-align: right;
}
</style>
</head>
<body>
<div class="row">
<div class="label" id="year-label">year:</div>
<div class="bar-container">
<div class="bar" id="year-bar"></div>
</div>
<div class="percent" id="year-pct"></div>
</div>
<div class="row">
<div class="label" id="week-label">week:</div>
<div class="bar-container">
<div class="bar" id="week-bar"></div>
</div>
<div class="percent" id="week-pct"></div>
</div>
<div class="row">
<div class="label" id="day-label">day:</div>
<div class="bar-container">
<div class="bar" id="day-bar"></div>
</div>
<div class="percent" id="day-pct"></div>
</div>
<script>
function update() {
const now = new Date();
/* ---------- Year ---------- */
const year = now.getFullYear();
const yearStart = new Date(year, 0, 1, 0, 0, 0);
const yearEnd = new Date(year + 1, 0, 1, 0, 0, 0);
const yearProgress = (now - yearStart) / (yearEnd - yearStart);
document.getElementById("year-label").textContent = `year: ${year}`;
document.getElementById("year-bar").style.width = `${yearProgress * 100}%`;
document.getElementById("year-pct").textContent = `${(yearProgress * 100).toFixed(1)}%`;
/* ---------- Week (Mon start) ---------- */
const day = now.getDay(); // 0=Sun
const diffToMonday = (day === 0 ? -6 : 1) - day;
const weekStart = new Date(now);
weekStart.setDate(now.getDate() + diffToMonday);
weekStart.setHours(0, 0, 0, 0);
const weekEnd = new Date(weekStart);
weekEnd.setDate(weekStart.getDate() + 7);
const weekProgress = (now - weekStart) / (weekEnd - weekStart);
const weekNumber = getWeekNumber(now);
document.getElementById("week-label").textContent = `week: ${weekNumber}th`;
document.getElementById("week-bar").style.width = `${weekProgress * 100}%`;
document.getElementById("week-pct").textContent = `${(weekProgress * 100).toFixed(1)}%`;
/* ---------- Day ---------- */
const dayStart = new Date(now);
dayStart.setHours(0, 0, 0, 0);
const dayEnd = new Date(dayStart);
dayEnd.setDate(dayStart.getDate() + 1);
const dayProgress = (now - dayStart) / (dayEnd - dayStart);
const mm = String(now.getMonth() + 1).padStart(2, "0");
const dd = String(now.getDate()).padStart(2, "0");
document.getElementById("day-label").textContent = `day: ${mm}/${dd}`;
document.getElementById("day-bar").style.width = `${dayProgress * 100}%`;
document.getElementById("day-pct").textContent = `${(dayProgress * 100).toFixed(1)}%`;
}
/* ローカルタイム準拠の週番号 ISO標準とはちょっと違うが別にそこは気にしてないんで... */
function getWeekNumber(date) {
const year = date.getFullYear();
// その年の1/1
const jan1 = new Date(year, 0, 1);
jan1.setHours(0, 0, 0, 0);
// 月曜始まり(0=Sun → 6)
const jan1Day = jan1.getDay();
const diffToMonday = (jan1Day === 0 ? -6 : 1) - jan1Day;
// 第1週の開始(月曜)
const firstWeekStart = new Date(jan1);
firstWeekStart.setDate(jan1.getDate() + diffToMonday);
// 現在の週の開始
const now = new Date(date);
const nowDay = now.getDay();
const diffNowToMonday = (nowDay === 0 ? -6 : 1) - nowDay;
const currentWeekStart = new Date(now);
currentWeekStart.setDate(now.getDate() + diffNowToMonday);
currentWeekStart.setHours(0, 0, 0, 0);
const weekIndex =
Math.floor((currentWeekStart - firstWeekStart) / (7 * 24 * 60 * 60 * 1000));
return weekIndex + 1;
}
update();
setInterval(update, 60 * 1000);
</script>
</body>
</html>