datetimepicker icon indicating copy to clipboard operation
datetimepicker copied to clipboard

Selects 1 Hour Before

Open lukepolo opened this issue 8 years ago • 15 comments

When opening up the selection for date / time it will be 1 hour wrong. Look below at screenshots to see :

<input type="text" id="start_date_time" name="start_date_time" class="datetimepicker required" value="{{ $meeting->start_date_time->format('m/d/y g:i A') }}" />

  <input type="text" name="end_time" class="timepicker required" value="{{ $meeting->end_time->format('g:i A') }}" />
        // Date and Time Picker
        $('.datetimepicker').datetimepicker({
            format: 'm/d/y g:i A',
            formatTime: 'g:i A',
            step: 30,
            startDate: $('input[name="date_start"]').val(),
            minDate: $('input[name="date_min"]').val(),
            maxDate: $('input[name="date_max"]').val()
        });

screen shot 2016-04-27 at 12 13 05 pm screen shot 2016-04-27 at 12 13 18 pm

lukepolo avatar Apr 27 '16 16:04 lukepolo

Same here. Seems to be broken when using 12 hour times with AM/PM. I found that v2.4.5 is the last version that works with my setup (2.4.6 results in JS errors, 2.4.7+ subtracts an hour).

I format the time using ruby

datetime = datetime.strftime('%Y-%m-%d %l:%M %p').squeeze(' ')

setup

$('#post_published_at').datetimepicker
  format: 'Y-m-d g:i A'
  formatTime: 'g:i A'
  scrollMonth: false

dsandstrom avatar Apr 29 '16 17:04 dsandstrom

@xdan I use v2.5.4 ,this issue is still there , when I changed time to 24 hour formate , it worked well. Following is my code:
book.date_time_picker_end = (tomorrow.getMonth() + 1) + '/' + tomorrow.getDate() + '/' + tomorrow.getFullYear() + ' ' + "01:00 PM"; $('#date_time_picker_end').datetimepicker({ value: (tomorrow.getMonth() + 1) + '/' + tomorrow.getDate() + '/' + tomorrow.getFullYear() + ' ' + "01:00 PM", step: 10, minDate: ' date.getFullYear()+' / '+(date.getMonth()+1)+' / '+date.getDate() ', format: 'm/d/Y h:i A', formatTime: 'h:i A', onChangeDateTime: function (dp, $input) { var endTimeNow = book.date_time_picker_end; var startTime = parseInt(new Date(book.date_time_picker_start).valueOf() + ""); var endTime = parseInt(new Date(dp).valueOf() + ""); console.log("end time ip is v",$input); console.log("end time ip is t",new Date($input.val()).valueOf()+""); console.log("end time dp is v",dp); console.log("end time dp is t",new Date(dp).valueOf()+""); console.log("end time et is v",book.date_time_picker_end); console.log("end time et is t",new Date(book.date_time_picker_end).valueOf()+""); if (endTime <= startTime) { MessageBox.toast("End time must be later than appointment time"); // book.date_time_picker_end = endTimeNow; $('#date_time_picker_end').val(endTimeNow); } else { book.date_time_picker_end = $input.val(); } } });

TLideaCreator avatar May 30 '16 07:05 TLideaCreator

I have the same problem!

It is with specifies the format property: "d/m/Y g:i A"

Any solution for this?

Thanks in advance!

Dimigergo avatar Nov 22 '16 13:11 Dimigergo

I believe the issue is with php-date-formatter.js version 1.3.3 in the method parseDate.

Try replacing this:

                    case 'g':
                    case 'h':
                        vMeriIndex = (vFormatParts.indexOf('a') > -1) ? vFormatParts.indexOf('a') :
                            (vFormatParts.indexOf('A') > -1) ? vFormatParts.indexOf('A') : -1;
                        mer = vDateParts[vMeriIndex];
                        if (vMeriIndex > -1) {
                            vMeriOffset = _compare(mer, vSettings.meridiem[0]) ? 0 :
                                (_compare(mer, vSettings.meridiem[1]) ? 12 : -1);
                            if (iDatePart >= 1 && iDatePart  -1) {
                                out.hour = iDatePart + vMeriOffset - 1;
                            } else if (iDatePart >= 0 && iDatePart = 0 && iDatePart 

with this:

                    case 'g':
                    case 'h':
                        vMeriIndex = (vFormatParts.indexOf('a') > -1) ? vFormatParts.indexOf('a') :
                            (vFormatParts.indexOf('A') > -1) ? vFormatParts.indexOf('A') : -1;
                        mer = vDateParts[vMeriIndex];
                        if (vMeriIndex > -1) {
                            vMeriOffset = _compare(mer, vSettings.meridiem[0]) ? 0 :
                                (_compare(mer, vSettings.meridiem[1]) ? 12 : -1);
                            if (iDatePart == 12 && vMeriOffset == 0)
                            {
                                out.hour = 0;
                            }
                            else if (iDatePart == 12 && vMeriOffset == 12)
                            {
                                out.hour = 12;
                            }
                            else if (iDatePart >= 1 && iDatePart  -1)
                            {
                                out.hour = iDatePart + vMeriOffset;
                            }
                            else if (iDatePart >= 0 && iDatePart = 0 && iDatePart 

ssugden avatar Dec 07 '16 00:12 ssugden

The solution is use a recent version of php-date-formatter, like 1.3.4. As I'm using https://github.com/shekibobo/xdan-datetimepicker-rails that comes with a .full version, which embeds php-date-formatter inside xdan-datetimepicker. I had to ignore the .full version and load the "not full version" + php-date-formatter.js 1.3.4 + jQuery Mousewheel.

thiagogabriel avatar Dec 20 '16 17:12 thiagogabriel

I'm also seeing this issue, is there any timeline on when it will be addressed?

lriggle-strib avatar Jan 12 '18 18:01 lriggle-strib

Same as #596

lriggle-strib avatar Feb 01 '18 16:02 lriggle-strib

I have the same kind of problem, but the "opposite" : I have one hour less into the input than on the timepicker list, when the input is initially blank. I use 24h format for time.

Maybe a problem about dealing with timezones (GMT+1 for me) ?

(Using version 2.5.4)

Maze-fr avatar Feb 07 '18 15:02 Maze-fr

I see this problem on version 2.5.20 using php-date-formatter 1.3.4.

glassdimly avatar Mar 29 '18 20:03 glassdimly

I am also seeing this issue using 2.5.20

owenbush avatar Sep 19 '18 21:09 owenbush

Still facing the same issue. Let us know if anybody found a solution to this

image

deepakmahakale avatar Mar 21 '19 18:03 deepakmahakale

The solution quoted on Dec 7, 2016 still works for us.

ssugden avatar Mar 21 '19 22:03 ssugden

apply this option, It is working fine validateOnBlur: false

gems-deepak avatar Feb 28 '20 16:02 gems-deepak

@gems-deepak validateOnBlur: false is not working in my case:

$('#appointmentSidebarDatetimeControl').datetimepicker({ step: 20, format: 'd-m-Y h:i A', formatTime: 'h:i A', formatDate: 'd-m-Y', validateOnBlur: false, });

bhaskardabhi avatar Jun 28 '21 13:06 bhaskardabhi

Hi, I have an equal problem with the DATE. I set the timezone to EUROPE/AMSTERDAM. I want the passed minutes between to given times. Next example: $begin = strtotime("12:00"); $end = strtotime("13:23"); $laptime = $end - $begin; echo date('H:i:s', $laptime); result is 02:23 !! When i don't set the timezone the result s 01:23 (as aspected).

Whit the timezone set to EUROPE/AMSTERAM the result of echo date('H:i:s', 0) is 01:00

Sietsedh avatar Aug 22 '22 10:08 Sietsedh