-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (29 loc) · 1.48 KB
/
app.js
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
setInterval(() => {
const today = new Date()
// day
const dayProgress = Math.round( ( ( today.getHours() * 60 + today.getMinutes() ) / 1440 ) * 100 )
let dayEl = document.getElementById("day-el")
dayEl.innerText = dayProgress + "%"
let dayPb = document.getElementById("day-pb")
dayPb.style.width = dayProgress + "%"
// week
const weekProgress = Math.round( ( ( today.getDay() * 1440 + today.getHours() * 60 + today.getMinutes() ) / 10080 ) * 100 )
let weekEl = document.getElementById("week-el")
weekEl.innerText = weekProgress + "%"
let weekPb = document.getElementById("week-pb")
weekPb.style.width = weekProgress + "%"
// month
const monthProgress = Math.round( ( today.getDate() / new Date(today.getFullYear(), today.getMonth() + 1, 0).getDate() ) * 100 )
let monthEl = document.getElementById("month-el")
monthEl.innerText = monthProgress + "%"
let monthPb = document.getElementById("month-pb")
monthPb.style.width = monthProgress + "%"
// year
// today - new Date(today.getFullYear(),0,1) returns milliseconds passed from start of the year
// 86400000 converts milliseconds to days
const yearProgress = Math.round( ( Math.ceil( ( today - new Date(today.getFullYear(),0,1) ) / 86400000 ) / 365 ) * 100 )
let yearEl = document.getElementById("year-el")
yearEl.innerText = yearProgress + "%"
let yearPb = document.getElementById("year-pb")
yearPb.style.width = yearProgress + "%"
}, 100)