-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
135 lines (114 loc) · 3.36 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
<!DOCTYPE html>
<html>
<head>
<title>Is it time for lunch?</title>
<link rel="shortcut icon" type="image/x-icon" href="assets/sandwhich.ico" />
<style>
{
margin: 0;
padding: 0;
outline: 0;
box-sizing: border-box;
font-family: sans-serif;
color: #333
}
.center {
display: flex;
flex-direction: column;
justify-content: center;
height: 100vh
}
.center.pending {
background: #FFA500
}
.center.success {
background: #47B800
}
.center.failure {
background: #FF0000
}
h1 {
font-size: 15vw;
width: 100%;
text-align: center
}
.pending h1,
.pending h2,
.success h1,
.success h2,
.failure h1,
.failure h2
{
color: #FFF
}
h2 {
font-size: 20px;
width: 100%;
text-align: center;
margin: 30px
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
$(function() {
var now = new Date(); // current time
// now.setHours(12,0,0,0); // for testing
var hours = now.getHours();
var minutes = now.getMinutes();
var lunchStart = new Date().setHours(11,30,0,0);
var lunchEnd = new Date().setHours(12,0,0,0);
function timeDifference(d, dd) {
var minute = 60 * 1000,
hour = minute * 60,
day = hour * 24,
month = day * 30,
ms = Math.abs(d - dd);
var months = parseInt(ms / month, 10);
ms -= months * month;
var days = parseInt(ms / day, 10);
ms -= days * day;
var hours = parseInt(ms / hour, 10);
ms -= hours * hour;
var minutes = parseInt(ms / minute, 10);
results = "";
if (hours > 0) {
results = hours + " hours and " + minutes + " minutes";
}
else {
results = minutes + " minutes";
}
return results;
};
if (hours == 11) {
if (minutes < 30) {
$(".center").addClass('pending');
$("h1").html("Almost!");
$("h2").html("Lunch starts in " + timeDifference(lunchStart, now) + ".");
} else {
$(".center").addClass('success');
$("h1").html("Time to eat!");
$("h2").html("Only " + timeDifference(lunchEnd, now) + " left.");
}
} else if (hours >= 12) {
//$(".center").removeClass('success');
$(".center").addClass('failure');
$("h1").html("Too late!");
$("h2").html("Lunch ended " + timeDifference(now, lunchEnd) + " ago.");
}
else {
$(".center").removeClass('success');
$(".center").removeClass('pending');
$(".center").removeClass('failure');
$("h1").html("Not yet");
$("h2").html("Lunch starts in " + timeDifference(lunchStart, now) + ".");
}
});
</script>
</head>
<body>
<div class="center">
<h1></h1>
<h2></h2>
</div>
</body>
</html>