-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
159 lines (150 loc) · 6.01 KB
/
index.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
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
159
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Arthur Machen</title>
<link rel="icon" href="favicon-32.png">
<style>
body{
color: #e3f2fd;
background: #64b5f6;
text-align: center;
font-family: sans-serif;
font-weight: 100;
}
h1{
margin: 40px 0 20px;
font-weight: 100;
font-size: 40px;
}
#clockContainer{
display: inline-block;
text-align: center;
font-size: 30px;
}
#clockContainer > div{
display: inline-block;
padding: 10px;
background: #1e88e5;
border-radius: 3px;
}
#clockContainer div > span{
display: inline-block;
padding: 15px;
background: #1976d2;
border-radius: 3px;
}
.smalltext{
padding-top: 5px;
font-size: 16px;
}
</style>
</head>
<body>
<h1>Arthur Machen</h1>
<div id="clockContainer">
<div>
<span class="years"></span>
<div class="smalltext">Ans</div>
</div>
<div>
<span class="months"></span>
<div class="smalltext">Mois</div>
</div>
<div>
<span class="days"></span>
<div class="smalltext">Jours</div>
</div>
<div>
<span class="hours"></span>
<div class="smalltext">Heures</div>
</div>
<div>
<span class="minutes"></span>
<div class="smalltext">Minutes</div>
</div>
<div>
<span class="seconds"></span>
<div class="smalltext">Secondes</div>
</div>
</div>
<script>
(function (window, document) {
var HowLongSince = function () {};
HowLongSince.prototype.getDiffYear = function (dateMin, dateMax) {
var diff = dateMax.getFullYear() - dateMin.getFullYear(),
earlierInYear = dateMax.getMonth() < dateMin.getMonth(),
earlierInMonth = dateMax.getMonth() == dateMin.getMonth() &&
dateMax.getDate() < dateMin.getDate();
if (earlierInYear || earlierInMonth) {
diff--;
}
return diff;
};
HowLongSince.prototype.getDiffMonth = function (dateMin, dateMax) {
var diff = dateMax.getMonth() - dateMin.getMonth();
if (diff < 0) {
diff += 12;
}
if (dateMax.getDate() < dateMin.getDate()) {
diff--;
}
return diff;
};
HowLongSince.prototype.getDiffDay = function (dateMin, dateMax) {
var diff = dateMax.getDate() - dateMin.getDate();
if (diff < 0) {
var year = dateMax.getFullYear();
var month = dateMax.getMonth() - 1;
if (month === -1) {
month = 11;
year--;
}
diff = new Date(year, month, 0).getDate() + diff;
}
return diff;
};
HowLongSince.prototype.getTimeCut = function (dateMin, dateMax) {
var t = Math.floor(dateMax.getTime() / 1000) - Math.floor(dateMin.getTime() / 1000);
return {
'total': t,
'years': this.getDiffYear(dateMin, dateMax),
'months': this.getDiffMonth(dateMin, dateMax),
'days': this.getDiffDay(dateMin, dateMax),
'hours': Math.floor(t / (60 * 60)) % 24,
'minutes': (Math.floor(t / 60)) % 60,
'seconds': t % 60
};
};
function initializeClock(id, starttime) {
var
howLong = new HowLongSince(),
dateStart = new Date(starttime),
clock = document.getElementById(id),
spanYears = clock.querySelector('.years'),
spanMonths = clock.querySelector('.months'),
spanDays = clock.querySelector('.days'),
spanHours = clock.querySelector('.hours'),
spanMinutes = clock.querySelector('.minutes'),
spanSeconds = clock.querySelector('.seconds');
function prefixWithZero(number) {
return ('0' + number).slice(-2);
}
function updateClock() {
var t = howLong.getTimeCut(dateStart, new Date());
spanYears.innerHTML = prefixWithZero(t.years);
spanMonths.innerHTML = prefixWithZero(t.months);
spanDays.innerHTML = prefixWithZero(t.days);
spanHours.innerHTML = prefixWithZero(t.hours);
spanMinutes.innerHTML = prefixWithZero(t.minutes);
spanSeconds.innerHTML = prefixWithZero(t.seconds);
}
updateClock();
window.setInterval(updateClock, 1000);
}
var birthday = 'Sat Aug 15 2015 08:12:00';
initializeClock('clockContainer', birthday);
})(window, document);
</script>
</body>
</html>