Bugfix for incorrect date: was previously chainging date with UTC timezone instead of local.

This commit is contained in:
Jason Williams 2018-08-19 18:48:11 -06:00
parent c24a260de2
commit a8765be426

View File

@ -55,7 +55,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=&AIzaSyCo79O07nOpWmdxKBUdgslJRrBwYSykDxwv=3.exp"></script> <script src="https://maps.googleapis.com/maps/api/js?key=&AIzaSyCo79O07nOpWmdxKBUdgslJRrBwYSykDxwv=3.exp"></script>
<script> <script>
var map; var map, today = new Date(), days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
$(function() { $(function() {
var locConnaught = new google.maps.LatLng(51.0426695, -114.0898373); var locConnaught = new google.maps.LatLng(51.0426695, -114.0898373);
@ -98,27 +98,37 @@
function updatePlan() { function updatePlan() {
$.getJSON('?calendar', function(data) { $.getJSON('?calendar', function(data) {
var today = new Date(), d1 = new Date(), d2 = new Date(), d3 = new Date();
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
d1.setDate(nextWorkday(today)); d1 = nextWorkday(today);
d2.setDate(nextWorkday(d1)); d2 = nextWorkday(d1);
d3.setDate(nextWorkday(d2)); d3 = nextWorkday(d2);
$('#plantitle').html('Three Day Plan'); $('#plantitle').html('Three Day Plan');
if (data.find(x => x.start.date == d1.toISOString().substr(0, 10))) $('#d1').html(days[d1.getDay()] + "<br>" + data.find(x => x.start.date == d1.toISOString().substr(0, 10)).summary); else $('#d1').html(days[d1.getDay()] + "<br><i>No Plan</i>");
if (data.find(x => x.start.date == d2.toISOString().substr(0, 10))) $('#d2').html(days[d2.getDay()] + "<br>" + data.find(x => x.start.date == d2.toISOString().substr(0, 10)).summary); else $('#d2').html(days[d2.getDay()] + "<br><i>No Plan</i>"); if (data.find(x => x.start.date == getYMDstring(d1))) $('#d1').html(days[d1.getDay()] + "<br>" + data.find(x => x.start.date == getYMDstring(d1)).summary); else $('#d1').html(days[d1.getDay()] + "<br><i>No Plan</i>");
if (data.find(x => x.start.date == d3.toISOString().substr(0, 10))) $('#d3').html(days[d3.getDay()] + "<br>" + data.find(x => x.start.date == d3.toISOString().substr(0, 10)).summary); else $('#d3').html(days[d3.getDay()] + "<br><i>No Plan</i>"); if (data.find(x => x.start.date == getYMDstring(d2))) $('#d2').html(days[d2.getDay()] + "<br>" + data.find(x => x.start.date == getYMDstring(d2)).summary); else $('#d2').html(days[d2.getDay()] + "<br><i>No Plan</i>");
if (data.find(x => x.start.date == getYMDstring(d3))) $('#d3').html(days[d3.getDay()] + "<br>" + data.find(x => x.start.date == getYMDstring(d3)).summary); else $('#d3').html(days[d3.getDay()] + "<br><i>No Plan</i>");
}); });
} }
function nextWorkday(d) { function nextWorkday(d) {
var day = d.getDay(), ddif = 1; var nd = new Date(d.getTime());
var day = nd.getDay(), ddif = 1;
if (day === 5) ddif = 3; if (day === 5) ddif = 3;
else if (day === 6) ddif = 2; else if (day === 6) ddif = 2;
return d.getDate() + ddif; nd.setDate(nd.getDate() + ddif);
return nd;
}
function getYMDstring(d) {
var output = '';
output += d.getFullYear() + '-';
output += (d.getMonth() < 9) ? '0' + (d.getMonth() + 1) : d.getMonth() + 1;
output += (d.getDate() < 10) ? '-0' + d.getDate() : '-' + d.getDate();
return output;
} }
</script> </script>
<body> <body>