-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
112 lines (88 loc) · 3.79 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
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
// current time
function currentTime() {
let actual_time = document.getElementById('actual_time');
let actual_days = document.getElementById('actual_days');
let suffix;
const date = new Date();
const dayOfMonth = date.getDate();
if (dayOfMonth === 1 || dayOfMonth === 21 || dayOfMonth === 31) {
suffix = "st";
} else if (dayOfMonth === 2 || dayOfMonth === 22) {
suffix = "nd";
} else if (dayOfMonth === 3 || dayOfMonth === 23) {
suffix = "rd";
} else {
suffix = "th";
}
function updateTime() {
const now = new Date();
const optionsTime = {
hour12: false,
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZone: 'Africa/Kigali'
};
const optionsDate = {
weekday: 'long',
month: 'long',
day: 'numeric',
};
const timeString = now.toLocaleString('en-US', optionsTime);
const dateString = now.toLocaleString('en-US', optionsDate);
actual_time.innerHTML = timeString;
actual_days.innerHTML = dateString.replace(',', '') + `<sup>${suffix}</sup>`;
}
setInterval(updateTime, 1000);
}
// birth day time
function birthDayTime() {
let actual_time = document.getElementById('actual_time');
let actual_days = document.getElementById('actual_days');
const birthDate = new Date('2002-06-10');
const currentDate = new Date();
const diffTime = Math.abs(currentDate - birthDate);
const diffYears = Math.floor(diffTime / (1000 * 60 * 60 * 24 * 365));
const diffMonths = Math.floor((diffTime / (1000 * 60 * 60 * 24 * 30.44)) % 12);
const diffDays = Math.floor((diffTime / (1000 * 60 * 60 * 24)) % 30.44);
const formattedTime = '<span style="font-size: 4rem; letter-spacing: 8px;">' + diffYears + ' Years ' + diffMonths + ' Months ' + diffDays + ' Days</span>';
actual_time.innerHTML = formattedTime;
const birthdayDate = new Date('2023-06-10');
const daysLeft = Math.floor((birthdayDate - currentDate) / (1000 * 60 * 60 * 24));
const formattedDays = daysLeft + ' Days until Derrick\'s 21st Birthday!';
actual_days.innerHTML = formattedDays;
}
// SECONDARY TIMER
function secondaryTime() {
let actual_time = document.getElementById('actual_time');
let actual_days = document.getElementById('actual_days');
const birthDate = new Date('2021-08-01');
const currentDate = new Date();
const diffTime = Math.abs(currentDate - birthDate);
const diffYears = Math.floor(diffTime / (1000 * 60 * 60 * 24 * 365));
const diffMonths = Math.floor((diffTime / (1000 * 60 * 60 * 24 * 30.44)) % 12);
const diffDays = Math.floor((diffTime / (1000 * 60 * 60 * 24)) % 30.44);
const formattedTime = '<span style="font-size: 4rem; letter-spacing: 8px;">' + diffYears + ' Year ' + diffMonths + ' Months ' + diffDays + ' Days</span>';
actual_time.innerHTML = formattedTime;
const birthdayDate = new Date('2021-08-01');
const daysLeft = Math.floor((currentDate - birthdayDate) / (1000 * 60 * 60 * 24));
const formattedDays = daysLeft + ' Days Since You Finished Secondary School!';
actual_days.innerHTML = formattedDays;
}
// UNIV-TIMER
function universityTime() {
let actual_time = document.getElementById('actual_time');
let actual_days = document.getElementById('actual_days');
const birthDate = new Date('2022-06-16');
const currentDate = new Date();
const diffTime = Math.abs(currentDate - birthDate);
// const diffYears = Math.floor(diffTime / (1000 * 60 * 60 * 24 * 365));
const diffMonths = Math.floor((diffTime / (1000 * 60 * 60 * 24 * 30.44)) % 12);
const diffDays = Math.floor((diffTime / (1000 * 60 * 60 * 24)) % 30.44);
const formattedTime = '<span style="font-size: 4rem; letter-spacing: 8px;">' + diffMonths + ' Months ' + diffDays + ' Days</span>';
actual_time.innerHTML = formattedTime;
const birthdayDate = new Date('2022-06-16');
const daysLeft = Math.floor((currentDate - birthdayDate) / (1000 * 60 * 60 * 24));
const formattedDays = daysLeft + ' Days Since You Joined University!';
actual_days.innerHTML = formattedDays;
}