trentrichardson / jQuery-Timepicker-Addon

Adds a timepicker to jQueryUI Datepicker
http://trentrichardson.com/examples/timepicker/
MIT License
2.66k stars 1.05k forks source link

timezoneAdjust fails if date is null or undefined #587

Open AGiorgetti opened 11 years ago

AGiorgetti commented 11 years ago

There should be a check to test if the date we are setting is null or undefined and in that case do not try to adjust for the timezone: changing the function to something like:

$.timepicker.timezoneAdjust = function (date, toTimezone) {
        if (date) {
            var toTz = $.timepicker.timezoneOffsetNumber(toTimezone);
            if (!isNaN(toTz)) {
                var currTz = date.getTimezoneOffset() * -1,
                    diff = currTz - toTz; // difference in minutes

                date.setMinutes(date.getMinutes() + diff);
            }
        }
        return date;
    };

was enough for my case. The problem arose when using a framework that supports two way data-binding like Knockoutjs or Angularjs.

Thanks for your great work, this control has been very helpful for me! Alessandro

lgBatista commented 11 years ago

I've the same problem, but i'm using two inputs together for the date controler with this solution, despite that the error not appear, the value of the first input disapears. What I can do about that ?