-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (44 loc) · 1.56 KB
/
script.js
File metadata and controls
52 lines (44 loc) · 1.56 KB
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
function init() {
var publicSpreadsheetUrl = 'https://docs.google.com/spreadsheets/d/18xGU3_X0DxJ44wNDljPXkVntO-h1umbmWQHd1T-CQ0Y/pubhtml';
Tabletop.init( { key: publicSpreadsheetUrl, callback: function(data, tabletop) {
var nextdate = findNextDate(data)
$(".calendar_top").html(nextdate[0])
$(".calendar_day").html(nextdate[1])
},
simpleSheet: true } )
}
function getCurrentDate() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
var today = { month:parseInt(mm),day:parseInt(dd),year:parseInt(yyyy)};
return today;
}
function formatDate(date) {
var dateArray = date.split("/");
var intDateObject = { month:parseInt(dateArray[0]), day:parseInt(dateArray[1]), year:parseInt(dateArray[2])}
return intDateObject;
}
function compareTwoDates(currentDate,upcomingDate) {
if (currentDate.month < upcomingDate.month) { // different month
return true;
}
else if (currentDate.month == upcomingDate.month) { // same month, different day
if (currentDate.day <= upcomingDate.day ) {
return true;
}
return false;
}
}
function findNextDate(allUpcomingDates) {
for (var i = 0; i < allUpcomingDates.length;i++) {
var current_date = getCurrentDate(); // current date: mm/dd/yyyy
var upcoming_date = formatDate(allUpcomingDates[i].rawdate); // upcoming date: mm/dd/yyyy
if ( compareTwoDates(current_date,upcoming_date) ) {
return [allUpcomingDates[i].month, allUpcomingDates[i].day];
}
}
return["none","none"]
}
init()