-
Notifications
You must be signed in to change notification settings - Fork 1
/
logic.js
71 lines (55 loc) · 2.1 KB
/
logic.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
//-------SETUP
//name, location, number
var oneLoc = new Location(firstPerson, firstLocation, 'one'); //first person's name as string, location (City, Country) as string
//name, location, number
var twoLoc = new Location(secondPerson, secondLocation, 'two'); //first person's name as string, location (City, Country) as string
//last day of contact (year, month, day)
var timeLeaveStamp = new Date(2020, 01, 01);
//first day of renewed contact (year, month, day)
var timeMeetStamp = new Date(2024, 11, 25);
//earliest and latest time appropirate for call
var earliestCall = 8;
var latestCall = 2;
//-------LOGIC
//location data
oneLoc.loadData();
twoLoc.loadData();
//time separation data
var today = new Date();
var totalTime = dateDiff('d', timeLeaveStamp, timeMeetStamp);
var timeApart = dateDiff('d', timeLeaveStamp, today);
var timeTillMeet = dateDiff('d', today, timeMeetStamp) + 1;
if (timeTillMeet <= 0) timeTillMeet = 0;
if (totalTime < timeApart) timeApart = totalTime;
var heartRate = 1.084;
var heartbeats;
//fill header
var pageTitle = document.getElementById('page-title');
pageTitle.innerHTML = oneLoc.name + ' + ' + twoLoc.name;
//fill dates
var separate = document.getElementById('time-separate');
separate.innerHTML = 'Time apart: ' + timeApart + ' days.';
var together = document.getElementById('time-till-meet');
together.innerHTML = 'Time until meet: ' + timeTillMeet + ' days.';
//move progress bar
var bar = document.getElementById('heartbeats');
bar.style.width = (timeApart / totalTime) * 100 + '%';
//get time difference between two dates in custom format
function dateDiff(datetype, fromdate, todate) {
datetype = datetype.toLowerCase();
var diff = todate - fromdate;
var divideBy = {w:604800000,
d:86400000,
h:3600000,
m:60000,
s:1000};
return Math.floor(diff/divideBy[datetype]);
}
//update heartbeat count
var beats = document.getElementById('heartbeats-left');
setInterval(function() {
today = new Date();
heartbeats = Math.floor(dateDiff('s', today, timeMeetStamp) * heartRate);
if (heartbeats < 1) heartbeats = 0;
beats.innerHTML = heartbeats + ' heartbeats away';
}, 500);