Skip to content

Cannot set time zone via 'option' #796

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
756gzdz5 opened this issue Mar 25, 2015 · 3 comments
Open

Cannot set time zone via 'option' #796

756gzdz5 opened this issue Mar 25, 2015 · 3 comments

Comments

@756gzdz5
Copy link

On http://trentrichardson.com/examples/timepicker/, I tried $('#timezone_example_1').datetimepicker('option', 'timezone', 60), but the timezoneoption keeps getting ignored. Only setting it using the dropdown list works. Is that a bug or am I doing something wrong?

@solhuebner
Copy link

Maybe the same like #223

@joshstrange
Copy link

I don't think it is the same thing... I'm running into the same issue. Calling:

$('#timezone_example_1').datetimepicker('option', 'timezone', "America/New_York")

What is stored in tp_inst.timezone doesn't change.

I don't want to change the time + timezone, just the value of the dropdown but I can't seem to figure out how best to do this.

@joshstrange
Copy link

Ok, I've gone with a brute force approach on this one...

if(!_.isNull(tp_inst.timezone_select)) {
    tp_inst.timezone_select.val(timezone).trigger('change');
} else {
    tp_inst.timezone = timezone;
    tp_inst._onTimeChange();
    tp_inst._onSelectHandler();
    tp_inst._afterInject();
}

Where:

timezone: This may be an offset for you or something like ET/CT/PT depending on if you are passing in a timezone map. You can see what this value is by inspecting the timezone dropdown and looking at the values for the options

tp_inst: Reference to the timepicker instance, you can get this by with the following code:

tp_inst = $.datepicker._get(datePickerJqueryElement.data('datepicker'), 'timepicker');

You might be asking, "why not always just use the second block of the if?" and I tried that but it appears that is not enough once the select is created. The second block is only ever needed if you want to change the TZ BEFORE opening the datetimepicker for the first time.

Also it's important to note this DOES NOT modify the date/time in any way. It simply changes the TZ so the original date and final date will not be equal just like 1pm EST != 1pm CST.

I've wrapped up the above code in a setTimezone function in our JS class that wraps this library (to handle other oddities) and I have a tp_inst defined on "this" which means I don't have to get the tp_inst every time this code is called. That said a .data() is not very expensive so yeah...

PS: I'm on 1.5.5 and I also have functions to get/set the date via unix timestamps as Date in the browser is super messed up due to having no concept of TZ, if that will help anyone let me know.

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