Skip to content
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

setDateTime sets DatePicker date to default date as of jQueryUI 1.8.14 #5

Closed
rmcouat opened this issue Jul 2, 2011 · 8 comments
Closed

Comments

@rmcouat
Copy link

rmcouat commented Jul 2, 2011

jQueryUI 1.8.14 fixed a bug in date setting which causes the setDate option to accept only the date portion of a date time string.

In the 1.4 (latest) release line 1121 I changed the line

                $.datepicker._setDate(inst, date, noChange);

to be

                $.datepicker._setDate(inst, date.split(' ')[0], noChange);

For more context here is the listing of the entire block

            if (typeof date == 'object' && date!==null) {
                $.datepicker._setDate(inst, new Date(date.getTime()), noChange);
            }
            else {
                $.datepicker._setDate(inst, date.split(' ')[0], noChange);
            }

I suspect there might be a problem with the typeof date == 'object' branch 3 lines above as well but I have not seen it, it may be filtered in the DatePicker code.

The patch made it work for me but I may not have taken the completely correct approach such as using space as the date and time separator.

Thanks,
Ron McOuat

@manfer
Copy link
Owner

manfer commented Jul 4, 2011

I'm looking into this and seems a little more complicated. I haven't checked your solution because that would only work for the default date format, for other formats that contain no breaking spaces will not work. As for the object part that should not fail as that is used when the date is a javascript date object instead of a date string.

I'm trying to determine if it could be a bug in jquery ui datepicker as the problem does not happen with dates in formats like DayofWeek, DayofMonth Month Year. I was thinking of a problem in parseDate function but if I run code like:

$.datepicker.parseDate("mm/dd/yy", "10/21/2011 10:30");

it is parsed correctly to the correct date no matter the appended time. So I haven't found the source of this yet.

I found a problem too that will be corrected with this. The syntax:

$(element).dateplustimepicker("setDate", "a date string");

is not working to set the date. And as it is now only works calling datepicker directly, with syntax like:

$(element).datepicker("setDate", "a date string");

Still working on it.

Thanks for the report,
manfer

@manfer
Copy link
Owner

manfer commented Jul 4, 2011

I'm wrong about the parseDate. I was testing the wrong version, 1.8.10. But in the newer version you report yes the parseDate triggers an error: "Extra/unparsed characters found in date: xx:xx" and no matter the date format. I continue looking into this.

@rmcouat
Copy link
Author

rmcouat commented Jul 4, 2011

In the report I left, the setDateTime I passed in was "2011/06/29
10:30:00" for example. The problem was the entire string is passed over
to DatePicker in the setDate portion of the call so the solution I put
in the report worked for me by stripping off the time portion of the string.

On 11-07-04 4:49 AM, manfer wrote:

I'm wrong about the parseDate. I was testing the wrong version, 1.8.10. But in the newer version you report yes the parseDate triggers an error: "Extra/unparsed characters found in date: xx:xx" and no matter the date format. I continue looking into this.

@manfer
Copy link
Owner

manfer commented Jul 4, 2011

I think I have solved this. I wanted to try a more general approach valid for any date format. This issue has made me realize I was not taking that approach in the function that sets time from a datetime string.

What I'm doing in my solution is, with the help of the configured time format for the picker, I divide the datetime string into a date string and a time string (just searching for the time with a builded regular expression).

I'm going to recheck and test it, and I will push it as soon as possible.

Regards,
manfer

@rmcouat
Copy link
Author

rmcouat commented Jul 4, 2011

No hurry on my part, what I have is working for me or I can roll back to
jQueryUI-1.8.13, either solution works for now.
Thanks very much for your very active support of this plug-in. It has
been perfect for my purposes.
Ron

On 11-07-04 7:49 AM, manfer wrote:

I think I have solved this. I wanted to try a more general approach valid for any date format. This issue has made me realize I was not taking that approach in the function that sets time from a datetime string.

What I'm doing in my solution is, with the help of the configured time format for the picker, I divide the datetime string into a date string and a time string (just searching for the time with a builded regular expression).

I'm going to recheck and test it, and I will push it as soon as possible.

Regards,
manfer

@rmcouat
Copy link
Author

rmcouat commented Sep 13, 2011

Found a related problem with IE 8
Here is how I initialize DatePlusTimePicker in $(document).ready(function()

$('#inline-dateplustimepicker').dateplustimepicker({
    dateFormat: 'yy-mm-dd',
    timeFormat: 'hh:mm:ss',
    minDate: settings['min_date'],
    maxDate: settings['max_date'],
    onDateTimeChange: function(date, inst, from_picker) {
        if (from_picker) {
            date_time_str = date.format('Y-m-d_H-i-s');
            ajax(control_URL_base+"?t="+(new Date()).getTime()+"&dt="+date_time_str, '', '');
        }
    }
});

If I set the date and time in Firefox, Safari or IE 9 it works, IE 8 in error sets the time sliders to all 0 no matter what time is set.
$('#inline-dateplustimepicker').dateplustimepicker('setDateTime', settings['v_time']);
where settings['v_time'] is a date and time string with the correct formats separated by a space between the date and time e.g. "2011-09-13 11:25:30".

If I follow the setDateTime call with a setTime call then IE 8 works properly as follows:
$('#inline-dateplustimepicker').dateplustimepicker('setTime', settings['v_time'].split(' ')[1]);

If I try to split the setDateTime into a setDate followed by a setTime with the appropriate pieces of the date time string then the setDate does not work in any browser. My date format seems to work in setDateTime but not in setDate.

Ron

@manfer
Copy link
Owner

manfer commented Sep 14, 2011

I thought I had pushed the changes that correct this issue but hadn't. I had tested my changes working with jQuery 1.6.2 and jQuery UI 1.8.14

Now I had pushed it after confirming that it works with latest versions, jQuery 1.6.4 and jQuery UI 1.8.16. Released v0.5 of dateplustimepicker.

I hope that solves the issue. In my tests it seems no problem now to set the datetime together with any date and time formats. Hope you can confirm it too.

Thanks. Regards.

@rmcouat
Copy link
Author

rmcouat commented Sep 14, 2011

I thought maybe you had got very busy and I had a workaround until this IE8 problem popped up. I have verified it works for all browsers I am using and so will close the issue.

Many thanks
Ron

@rmcouat rmcouat closed this as completed Sep 14, 2011
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

2 participants