-
Notifications
You must be signed in to change notification settings - Fork 579
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
Bug with setValue: hours is 1hr less than selected #462
Comments
Please see this JSFiddle that contains the gist you posted and let me know if you can reproduce the bug there. On my Windows machine it seems to be setting the values correctly. If the JSFiddle is OK for you, then the issue is caused by some other code in your app. Are you setting the timezone for the |
Hi @monovertex, yes I am unable to reproduce this bug today. I tried to set my computer's time to yesterdays date (28 Oct 2018) and it is reproducible! See screenshot |
Hi @monovertex , what do you think about it? |
@Hirurg103 Sorry, I've been caught up with work and real life. I'm currently on a Linux machine, which gives me grief with date changes, I'll check it out on 28 October as soon as I get home on my Windows machine and come back with my feedback. |
@monovertex no problem at all. Thank you for the response! |
@Hirurg103, some first thoughts:
I'll have to take a look through the code and see where is the hour difference coming from, but this is definitely a confirmed bug now. PRs are welcome 😁. |
This is probably related to an issue I had. When function x() fires (the one that fires when you click a date), the math to determine date range is based on milliseconds. On November 4th this year the clocks rolled back 1 hour so technically November 4th is 25 hours long in countries that use daylight savings. So if you do an alert to spit out the times "a.start" and "a.end" you'll see a UTC offset such as My requirement was to make the maxdays=31 but because this range above is 31 days and 1 hour, daterangepicker rounds up to 32. I imagine you'll have a similar issue when daylight savings starts and you'll be able to select 1 day more than your date range, or the range will report as 1 day less. Your problem is likely similar to mine. Here's what I added at the very top of function x() to fix this issue. You might want to use this as starting point. This assumes that all dates are midnight, though: ` var mystart = new Date(a.start);
Essentially what you get is when datlight savings ends, the start date (before it ended) will have the same UTC offset as it did before, so the start date time thrown in the calculation will be 60 minutes shorter so the calculation will be exactly 31 days... or you could just subtract 60 minutes from the last day.. either way. |
Actually strike that second condition where "myend" is set. This takes a range that would be 30 days and 23 hours and adds 60 minutes to make the range an even 31, which is unnecessary because date range calcs in JS are going to round up to 31 anyways. However, if you're looking for exact time between ranges and not just days, I'd keep it in. |
Hello @monovertex @longbill . Could you please take a look at my PR that fixes this bug when you have time. Thank you! |
…T clocks change [fix #462] Before this commit the time calculated by the plugin was one hour more than the time selected by the user when the clocks move forward an hour and one hour less when the clocks move back for users in BST/DST regions. This happened because to calculate the selected time, the selected hours were added to the beginning of the selected day. For example, when user selected 02:00 on the day when the clocks move forward then the calculated time was 03:00 because the beginning of the day plus 2 hours is 03:00. This is due to the fact that at 01:00 the clocks move forward an hour. For more details see https://en.wikipedia.org/wiki/British_Summer_Time https://en.wikipedia.org/wiki/Daylight_saving_time In this commit the code was changed to use the hour/minute MomentJS functions to set time: https://momentjs.com/docs/#/get-set/hour https://momentjs.com/docs/#/get-set/minute
I use
setValue
to set date values in the app form. But the issue is that the displayed value is 1hr less than selected by the user.This bug is reproducible when I select Greenwich Mean Time time zone on my computer
I am adding a source code how to reproduce this bug:
There is a gist with this source code
The text was updated successfully, but these errors were encountered: