-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
164 lines (138 loc) · 6.21 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
160
161
162
163
164
<html>
<head>
<title>Time Calculator</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<style>
.form-signin { max-width: 330px; padding: 15px; margin: 0 auto; padding-top: 5px; } .form-signin .form-signin-heading, .form-signin .checkbox { margin-bottom: 10px; } .form-signin .checkbox { font-weight: normal; } .form-signin .form-control { position: relative; font-size: 16px; height: auto; padding: 10px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .form-signin .form-control:focus { z-index: 2; } .form-signin input[type="number"] { margin-bottom: 10px; } .account-wall { margin-top: 20px; padding: 40px 0px 20px 0px; background-color: #f7f7f7; -moz-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3); -webkit-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3); box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3); } .login-title { color: #555; font-size: 18px; font-weight: 400; display: block; } .profile-img { width: 96px; height: 96px; margin: 0 auto 10px; display: block; -moz-border-radius: 50%; -webkit-border-radius: 50%; border-radius: 50%; } .profile-name { font-size: 16px; font-weight: bold; text-align: center; margin: 10px 0 0; height: 1em; } .profile-email { display: block; padding: 0 8px; font-size: 15px; color: #404040; line-height: 2; font-size: 14px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; } .need-help { display: block; margin-top: 10px; } .new-account { display: block; margin-top: 10px; }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<div class="container">
<div class="input-box">
<div class="row">
<div class="col-sm-6 col-md-4 col-md-offset-4">
<div class="account-wall">
<p class="profile-name">Time Calculator</p>
<form class="form-signin">
<h4 class="warning text-center">Sunrise</h4>
<input id="dayHH" type="number" class="form-control" placeholder="HH" required autofocus>
<input id="dayMM" type="number" class="form-control" placeholder="MM" required autofocus>
<h4 class="success text-center">Sunset</h4>
<input id="nightHH" type="number" class="form-control" placeholder="HH" required autofocus>
<input id="nightMM" type="number" class="form-control" placeholder="MM" required autofocus>
<button class="btn btn-lg btn-primary btn-block" type="submit">Calculate</button>
<span class="clearfix"></span>
</form>
</div>
<h4 class="text-center new-account">All times are in 24-Hour format</h4>
</div>
</div>
</div>
<div class="result-box" style="display:none;">
<br/><br/>
<div class="table-responsive">
<table class="table">
<thead>
<tr class="danger">
<th colspan="2">1 hour in Day = <span id="dayMinutes"></span> Minutes</th>
</tr>
<tr class="danger">
<th colspan="2">1 hour in Night = <span id="nightMinutes"></span> Minutes</th>
</tr>
</thead>
</table>
</div>
<br/><button class="btn btn-lg btn-primary btn-block" id="newButton">New Calculation?</button> <br/>
<div class="table-responsive">
<table class="table">
<thead>
<tr class="success">
<th colspan="2">Day</th>
</tr>
<tr class="warning">
<th>From</th>
<th>To</th>
</tr>
</thead>
<tbody class="dayBody">
</tbody>
</table>
<div class="table-responsive">
<table class="table">
<thead>
<tr class="success">
<th colspan="2">Night</th>
</tr>
<tr class="warning">
<th>From</th>
<th>To</th>
</tr>
</thead>
<tbody class="nightBody">
</tbody>
</table>
</div>
</div>
<br/><button class="btn btn-lg btn-primary btn-block" id="newButton">New Calculation?</button> <br/>
</div>
</body>
<script type="text/javascript">
var start = function(dayHH,dayMM,nightHH,nightMM){
var setTime = function(hours, minutes){
var t = new Date();
t.setHours(hours);
t.setMinutes(minutes);
t.setSeconds(0);
t.setMilliseconds(0);
return t;
};
var calcDifference = function(end, start){
return ((end - start) / 1000) / 60;
};
var startTime = setTime(dayHH,dayMM);
var endTime = setTime(nightHH, nightMM);
var nightStartTime = setTime(dayHH,dayMM);
nightStartTime.setDate(nightStartTime.getDate()+1);
var MinutesDifferenceDay = calcDifference(endTime,startTime);
var differenceDay = MinutesDifferenceDay / 720;
var startCopy = startTime;
var MinutesDifferenceNight = calcDifference(nightStartTime,endTime);
var differenceNight = MinutesDifferenceNight / 720;
$("#dayMinutes").html(differenceDay*60);
$("#nightMinutes").html(differenceNight*60);
for(var i = 0; i <12; i++){
var minutesDay = differenceDay * 60;
var oldT = startTime.getHours() + ":" + startTime.getMinutes();
startTime.setMinutes(startTime.getMinutes() + minutesDay);
var newT = startTime.getHours() + ":" + startTime.getMinutes();
$(".dayBody").append("<tr><td>"+oldT+"</td><td>"+newT+"</td></tr>");
}
for(var i = 0; i <12; i++){
var minutesNight = differenceNight * 60;
var oldT = startTime.getHours() + ":" + startTime.getMinutes();
startTime.setMinutes(startTime.getMinutes() + minutesNight);
var newT = startTime.getHours() + ":" + startTime.getMinutes();
$(".nightBody").append("<tr><td>"+oldT+"</td><td>"+newT+"</td></tr>");
}
};
$(document).ready(function(){
$("#newButton").on('click',function(){
$(".input-box").show();
$(".result-box").hide();
});
$(".form-signin").on('submit', function(event){
event.preventDefault();
var dayHH = $("#dayHH").val();
var dayMM = $("#dayMM").val();
var nightHH = $("#nightHH").val();
var nightMM = $("#nightMM").val();
// hide this form
$(".input-box").hide();
$(".result-box").show();
start(dayHH,dayMM,nightHH,nightMM);
});
});
</script>
</html>