mugifly / jquery-simple-datetimepicker

Date & time picker for jQuery, It's simple & clean.
http://mugifly.github.com/jquery-simple-datetimepicker
Other
260 stars 182 forks source link

Issue with month jumping #98

Closed jcutrell closed 10 years ago

jcutrell commented 10 years ago

Looks like when the current month is January 31, clicking on the next month arrow skips a full month.

jcutrell commented 10 years ago

I managed to fix this with some monkey patching - not sure if it's suitable for a release, but it feels stable to me. It looks like the edge case occurs as a result of some of the input change/keyup event triggering causing multiple renderings, as well as an incorrect parsing for choosing the final day of the month if the current date (e.g. 31) is greater than next month's last day (e.g. 28).

lumpy2000 commented 10 years ago

Problem was with setting date parameters one-by-one as mentioned here: https://github.com/mugifly/jquery-simple-datetimepicker/issues/86

This is my temp. fix:

                while (df != null && 0 < df.length) {
                    var format_c = df.substring(0, 1); df = df.substring(1, df.length);
                    if (format_before_c != format_c) {
@@ -214,31 +214,33 @@
                    if(m.length < i){
                        break;
                    }

                    var f = formats[i];
                    var d = m[i+1]; // Matched part of date
+                   var setYear,setMonth,setDate,setHours,setMinutes;
                    if(f == 'YYYY'){
-                       date.setFullYear(normalizeYear(d));
+                       setYear=normalizeYear(d);
                        is_successful = true;
                    } else if(f == 'YY'){
-                       date.setYear(d);
+                       setYear=d;
                        is_successful = true;
                    } else if(f == 'MM' || f == 'M'){
-                       date.setMonth(parseInt(d) - 1);
+                       setMonth=(parseInt(d) - 1);
                        is_successful = true;
                    } else if(f == 'DD' || f == 'D'){
-                       date.setDate(d);
+                       setDate=d;
                        is_successful = true;
                    } else if(f == 'hh' || f == 'h'){
-                       date.setHours(d);
+                       setHours=d;
                        is_successful = true;
                    } else if(f == 'mm' || f == 'm'){
-                       date.setMinutes(d);
+                       setMinutes=d;
                        is_successful = true;
                    } 
+                   date = new Date(setYear,setMonth,setDate,setHours,setMinutes);
                }