Skip to content

"Now" button click sets a wrong Value for the default Timezone. #843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
andriiash opened this issue Nov 16, 2015 · 3 comments
Open

"Now" button click sets a wrong Value for the default Timezone. #843

andriiash opened this issue Nov 16, 2015 · 3 comments

Comments

@andriiash
Copy link

Use the next to reproduce:

$(function () {
        $('#MyTime').timepicker({
            timeFormat: 'TT hh:mm:ss',
            timeOnly: true
        });
    });

To reproduce:

  1. Click on Now button.
  2. Remember the Time value.
    3.Wait a few seconds.
  3. Click on Now button again.
  4. Compare a new value with the previous one.

For example, after the button click the "now" variable has value eqals "Mon Nov 16 2015 15:05:28 GMT+0200". The result of "now.getMinutes() + now.getTimezoneOffset() + tzoffset"
will be [5(int) + -120(int) + "120"(string)] equls "-115120" instead of 5 as expected, since "tzoffset" will have a string value for the default Timezone. Thus, after the now.setMinutes(-115120) call the date value will be elqual: "Fri Aug 28 2015 16:20:28 GMT+0300".

Fix:
The jquery-ui-timepicker-addon.js code:

$.timepicker.timezoneOffsetNumber = function (tzString) {
...
        if (!/^(\-|\+)\d{4}$/.test(normalized)) { // possibly a user defined tz, so just give it back
            return tzString;
        }
...
}

should be replaced by:

$.timepicker.timezoneOffsetNumber = function (tzString) {
...
        if (!/^(\-|\+)\d{4}$/.test(normalized)) { // possibly a user defined tz, so just give it back
            return parseInt(tzString);
        }
...
}
@trentrichardson
Copy link
Owner

I updated dev branch with this fix. Note that this completely kills the partial support that existed for custom alpha timezones (it was a use at your own risk anyway).

@andriiash
Copy link
Author

Thanks a lot!

@MrPetovan
Copy link

MrPetovan commented Jun 17, 2016

I found that this issue is actually coming from _onTimeChange which sets the timepicker timezone as a string:
Line 828 of jquery-ui-timepicker-addon.js version v1.6.1

if (timezone !== false) {
    timezone = timezone.toString();
}

I would suggest to change to:

if (timezone !== false) {
    timezone = parseInt(timezone);
}

In order to keep the user-defined timezones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants