fixed bug regarding timezone offset for html5 date input. arrival and departure dates...
authorAnthony Talarico <talarico@gaslightmedia.com>
Wed, 27 Jul 2016 14:48:03 +0000 (10:48 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Wed, 27 Jul 2016 14:48:03 +0000 (10:48 -0400)
js/app.js
js/custom/pageSetup.js

index 944a050..25da48e 100644 (file)
--- 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);
         }
index 69d7fcd..e766db5 100644 (file)
@@ -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);
         }