jonthornton / Datepair.js

A javascript plugin for intelligently selecting date and time ranges, inspired by Google Calendar.
https://www.jonthornton.com/Datepair.js
358 stars 87 forks source link

when value set on both dateinputs, the second dateinput doesn't change when second timeinput is set after midnight #73

Closed pixeldoris closed 8 years ago

pixeldoris commented 8 years ago

I have this problem with an application. I need to be able to alter the time-span of an already existing work shift in a certain event and the date needs to be altered automatically depending on the time.

I have this form which is automatically filled in with data from a database.

<input type="hidden" class="date start" value=" $startdate "> // 2016-05-18
<input type="text" class="time start" value=" $starttime "> // 18:00
<input type="hidden" class="date end" value=" $enddate"> // 2016-05-18
<input type="text" class="time end" value=" $endtime "> // 23:00

The problem is that when I set the $endtime input to, for example, 03:00 after midnight. The $starttime is set to 03.00 too instead of the $enddate changing to '2016-05-19'.

Is this fixable or do I need to go the extra mile and code something like:

$start = strtotime($starttime);
$end = strtotime($endtime);
$midnight = strtotime('00:00');

if ($end < $start AND $end > $midnight) {
    // Add one day to $enddate
} 

and skip the date inputs etc....

jonthornton commented 8 years ago

The end date should roll over automatically, and the start time should not change. Can you post a link that demonstrates the problem?

pixeldoris commented 8 years ago

I can't post the actual link since it's "the real deal" but maybe I can make a fiddle (never done it but I'll try) and if the fiddle works I might just have some code that's colliding with datepair. But I'll try to make a fiddle now..

pixeldoris commented 8 years ago

I can't get the fiddle to even work with the datepicker or timepicker.. but I did go the extra mile, so my application does work, but extra code is never nice.. :/ to bad I can't demonstrate my problem.

jonthornton commented 8 years ago

Try this as a starting point for the fiddle http://jsfiddle.net/jonthornton/dx8xkvnb/

pixeldoris commented 8 years ago

When I alter that one so that it has the same code as the website I'm working on it's working just fine.. I have no idea what's causing this bug on my page, but atleast now I know it's not the datepair..

pixeldoris commented 8 years ago

I have a videoclip when I'm demostrating, can I send it somewhere? so that you'll see?

jonthornton commented 8 years ago

Isolating the problem in a jsfiddle is the only way I can help. It's impossible to debug without code.

pixeldoris commented 8 years ago

it's so weird suddenly it works...

pixeldoris commented 8 years ago

I think I know when it doesn't work.. it's when I have a date that's already passed, since I don't allow to pick those dates it can't choose that... now it all makes sense.

jonthornton commented 8 years ago

https://en.wikipedia.org/wiki/Rubber_duck_debugging :)