From: Anthony Talarico Date: Wed, 27 Jul 2016 14:48:03 +0000 (-0400) Subject: fixed bug regarding timezone offset for html5 date input. arrival and departure dates... X-Git-Tag: v1.0.0^2~255 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=dbd63c8dcfa037c2fdf02a007d471771df8498de;p=WP-Themes%2Fpetoskeyarea.git fixed bug regarding timezone offset for html5 date input. arrival and departure dates should now be restricted properly. --- diff --git a/js/app.js b/js/app.js index 944a050..25da48e 100644 --- a/js/app.js +++ b/js/app.js @@ -81,46 +81,50 @@ $(document).ready(function () { $(departure_date).datepicker("show"); }); - var extraDay, end, arrival, currentDate, currentDate2, - requiredDate, requiredDate1, minDays, departure, - stay, d, dd, m, y; + var extraDay, end, arrival, currentDate, currentDate2, currentDatePlusOne, requiredDate, requiredDate1, minDays, departure, stay, d, dd, m,mm, y; + $(document).on('change', '#arriveOff', function () { currentDate = $("#arriveOff").val(); + currentDate = currentDate.replace(/-/g, "/"); + currentDate = new Date(currentDate); + currentDatePlusOne = new Date(currentDate); - // this section is used to circumvent issues with selecting the last day of the month without a proper rollover to the following month. - currentDate = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate()); - currentDate.setDate(currentDate.getDate()); + currentDatePlusOne.setDate(currentDate.getDate() + 1); - dd = currentDate.getDate() + 1; + dd = currentDatePlusOne.getDate(); if (dd <= 9) { dd = '0' + dd; } - d = currentDate.getDate(); + + console.debug(dd); + d = currentDate.getUTCDate(); if (d <= 9) { d = '0' + d; } - m = currentDate.getMonth() + 1; + m = currentDate.getUTCMonth() + 1; if (m <= 9) { m = '0' + m; } + mm = currentDatePlusOne.getUTCMonth() + 1; + if (mm <= 9) { + mm = '0' + mm; + } y = currentDate.getFullYear(); // this variable is for passing to booking site requiredDate = y + '-' + m + '-' + d; - minDays = y + '-' + m + '-' + dd; + minDays = y + '-' + mm + '-' + dd; $("#departOff").attr("min", minDays); - if (requiredDate <= $("#arriveOff").attr("min")) { - minDays = $("#arriveOff").attr("min"); - $("#arriveOff").val(minDays); - } + $("#departOff").val(""); + }); // restrict departure date /////////////////////////////// $(document).on('change', '#departOff', function () { currentDate2 = $("#departOff").val(); + currentDate2 = currentDate2.replace(/-/g, "/"); currentDate2 = new Date(currentDate2); - currentDate2 = new Date(currentDate2.getUTCFullYear(), currentDate2.getUTCMonth(),currentDate2.getUTCDate()); - currentDate2.setDate(currentDate2.getDate()); + if($("#departOff").val() <= requiredDate){ $("#departOff").val(minDays); } diff --git a/js/custom/pageSetup.js b/js/custom/pageSetup.js index 69d7fcd..e766db5 100644 --- a/js/custom/pageSetup.js +++ b/js/custom/pageSetup.js @@ -72,46 +72,50 @@ $(document).ready(function () { $(departure_date).datepicker("show"); }); - var extraDay, end, arrival, currentDate, currentDate2, - requiredDate, requiredDate1, minDays, departure, - stay, d, dd, m, y; + var extraDay, end, arrival, currentDate, currentDate2, currentDatePlusOne, requiredDate, requiredDate1, minDays, departure, stay, d, dd, m,mm, y; + $(document).on('change', '#arriveOff', function () { currentDate = $("#arriveOff").val(); + currentDate = currentDate.replace(/-/g, "/"); + currentDate = new Date(currentDate); + currentDatePlusOne = new Date(currentDate); - // this section is used to circumvent issues with selecting the last day of the month without a proper rollover to the following month. - currentDate = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate()); - currentDate.setDate(currentDate.getDate()); + currentDatePlusOne.setDate(currentDate.getDate() + 1); - dd = currentDate.getDate() + 1; + dd = currentDatePlusOne.getDate(); if (dd <= 9) { dd = '0' + dd; } - d = currentDate.getDate(); + + console.debug(dd); + d = currentDate.getUTCDate(); if (d <= 9) { d = '0' + d; } - m = currentDate.getMonth() + 1; + m = currentDate.getUTCMonth() + 1; if (m <= 9) { m = '0' + m; } + mm = currentDatePlusOne.getUTCMonth() + 1; + if (mm <= 9) { + mm = '0' + mm; + } y = currentDate.getFullYear(); // this variable is for passing to booking site requiredDate = y + '-' + m + '-' + d; - minDays = y + '-' + m + '-' + dd; + minDays = y + '-' + mm + '-' + dd; $("#departOff").attr("min", minDays); - if (requiredDate <= $("#arriveOff").attr("min")) { - minDays = $("#arriveOff").attr("min"); - $("#arriveOff").val(minDays); - } + $("#departOff").val(""); + }); // restrict departure date /////////////////////////////// $(document).on('change', '#departOff', function () { currentDate2 = $("#departOff").val(); + currentDate2 = currentDate2.replace(/-/g, "/"); currentDate2 = new Date(currentDate2); - currentDate2 = new Date(currentDate2.getUTCFullYear(), currentDate2.getUTCMonth(),currentDate2.getUTCDate()); - currentDate2.setDate(currentDate2.getDate()); + if($("#departOff").val() <= requiredDate){ $("#departOff").val(minDays); }