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

Already on GitHub? Sign in to your account

simple fix to allow override on timezone value #223

Open
hysterix opened this Issue Aug 7, 2011 · 11 comments

Comments

Projects
None yet

hysterix commented Aug 7, 2011

Hello,

I am creating an application, and your fork has helped me out a lot. I ran into a small problem, and that was trying to override the default value for timezone wasn't working, it was always defaulting to the hard-coded value, even though I was putting the correct information upon creating the object.

        $('#timet').datetimepicker({
            dateFormat: $.datepicker.RFC_2822,
            hourMin: 03,
            timeFormat: 'hh:mm z',
            timezone: '+0200',
            showTimezone: false
            });

The timezone field wasn't working, I tracked it down and my fix was as follows:

Inside the function _injectTimePicker, add this line:
// override default timezone value
this.timezone = o.timezone;

Before this line, "if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0 && o.showTimepicker) {"

That should allow you to override the default timezone value. Hope this saves someone else some time.

Yes this fixed it after spending hours!! thanks

Vimm2 commented Aug 19, 2011

That's great, I was just looking for how to make the "Now" button set the time in GMT instead of local time. Sounds like this is exactly what I need.

In the $.extend(TimePicker.prototype), _newInst function definition, there's a section where we build up a new instance and populate its fields with values from the _defaults object. I added the following:

tp_inst.timezone = tp_inst._defaults.timezone;

near the section of code where the hour, minute, etc... fields are assigned, like so:

tp_inst.timezone = tp_inst._defaults.timezone;
tp_inst.hour = tp_inst._defaults.hour;
tp_inst.minute = tp_inst._defaults.minute;
tp_inst.second = tp_inst._defaults.second;
tp_inst.millisec = tp_inst._defaults.millisec;
tp_inst.ampm = '';

Is this a correct alternative fix for this issue? (v.0.9.7)

This doesn't work for me. I've added the two fixes mentioned above, but if I try overriding the timezone to America/New_York and I set my local time to India Standard Time and click the "Now" button it always changes the value to India Standard Time.

hawk-ip commented Apr 27, 2012

I agree with redijedi - wilwayco fixes the problem, except if you click Now at which time the default TZ is put back into the input.

I just hid the Now button using CSS ;-)

fvox13 commented Jun 20, 2012

What would be involved in adding an option that made the "Now" button always use a timezone you specify? I've got a use-case for "Now" meaning "Now, in GMT" as well. Going to hide the Now button with CSS, but I'd love to have the functionality.

I need the same functionality as fvox13. I'm working a system where the user can pick a time zone they want all of their time zones in for both display end editing (it will often be a different time zone than the one they have their computer set to), and I need it so that clicking 'Now' yields a date/time in the selected time zone ... the way it works now it ALWAYS gives a the current date/time in the computer's local time zone.

gwikle commented Apr 6, 2015

+1 to fix this issue.
I also need the Now button to set a time in the configured zone. The fixes above did not work for me. Instead I overrode the $.datepicker._gotoToday method as shown below. This code can be put into your own javascript file so you don't have to modify the jQuery-Timepicker-Addon source code in the distribution. (This works with version 1.5.0 of jQuery-Timepicker-Addon. I have not tested any other version.)

    $.datepicker._gotoToday = function (id) {
        var inst = this._getInst($(id)[0]);
        this._base_gotoToday(id);
        var tp_inst = this._get(inst, 'timepicker');
        var tzoffset = $.timepicker.timezoneOffsetNumber(tp_inst.timezone);
        var now = new Date();
        now.setMinutes(now.getMinutes() + now.getTimezoneOffset() - tzoffset);
        this._setTime(inst, now);
        this._setDate(inst, now);
    };
'''

What is the status of this one?

mfrere commented May 15, 2015

I'd also like to see this feature implemented. (hitting "now" would fill the field with eg UTC)

Owner

trentrichardson commented Jun 14, 2015

I applied the changes mentioned by @gwikle however after further testing it was not working properly. For example in the docs the first example I press Now and I 17:50 when I should have gotten 11:50. I am at -0400 timezone so perhaps instead of subtracting it should have added the timezone (it would be negated tzoffset). I applied this tweak to the dev branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment