Implemented weekdays, weekends, invalid days
This commit is contained in:
parent
c616bbfde0
commit
12a0ed3ff0
1 changed files with 174 additions and 154 deletions
26
index.html
26
index.html
|
@ -59,6 +59,8 @@
|
|||
<script type="text/javascript">
|
||||
//=====
|
||||
|
||||
window.onload = function() {
|
||||
|
||||
var apiKey = "e98ccf69-6131-42ad-a11c-d733698dad63";
|
||||
//Above: test key, will return dummy data but is unlimited
|
||||
//Below: live key, returns actual data but limited per month
|
||||
|
@ -93,6 +95,8 @@
|
|||
var date = new Date(startYear, startMonth-1, startDay, 0, 0, 0, 0);
|
||||
|
||||
var outputDiv = document.getElementById("output");
|
||||
//TODO: if the outputTable already exists, remove it
|
||||
outputDiv.innerHTML = "";
|
||||
var outputTable = document.createElement("table");
|
||||
outputDiv.appendChild(outputTable);
|
||||
|
||||
|
@ -122,7 +126,7 @@
|
|||
//Special case: first row (or first day of the month)
|
||||
//Fill from Sunday to the day with blanks
|
||||
if (weekday != 0) {
|
||||
for (var j = weekday; j >= 0; j--){
|
||||
for (var j = weekday; j > 0; j--){
|
||||
var blank = document.createElement("td");
|
||||
blank.className = "invalid";
|
||||
weekRow.appendChild(blank);
|
||||
|
@ -140,10 +144,16 @@
|
|||
dayField.innerHTML = date.getUTCDate();
|
||||
weekRow.appendChild(dayField);
|
||||
|
||||
if (i >= numberOfDays - 1) {
|
||||
if (i >= numberOfDays - 1 || lastDay(date)) {
|
||||
//Special case: last row
|
||||
//In single-week outputs it can also be the first!
|
||||
keepLooping = false;
|
||||
if (weekday != 6) {
|
||||
for (var j = weekday; j < 6; j++){
|
||||
var blank = document.createElement("td");
|
||||
blank.className = "invalid";
|
||||
weekRow.appendChild(blank);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -151,6 +161,9 @@
|
|||
//weekRow.innerHTML = "TEST";
|
||||
outputTable.appendChild(weekRow);
|
||||
|
||||
//Iterate to the next day
|
||||
date = new Date(date.getTime() + 86400000);
|
||||
|
||||
//TODO: Set a new month marker when the month's done
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +239,14 @@
|
|||
}
|
||||
}
|
||||
|
||||
function lastDay(date) {
|
||||
var tomorrow = new Date(date.getTime() + 86400000);
|
||||
return (tomorrow.getUTCDate() == 1);
|
||||
}
|
||||
|
||||
document.getElementById("generate-button").onclick = generate();
|
||||
|
||||
}
|
||||
//=====
|
||||
</script>
|
||||
</body>
|
||||
|
|
Loading…
Add table
Reference in a new issue