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

date/time validation is not reliable #425

Open
vzverev78 opened this issue Apr 5, 2016 · 1 comment
Open

date/time validation is not reliable #425

vzverev78 opened this issue Apr 5, 2016 · 1 comment

Comments

@vzverev78
Copy link
Contributor

Due to used DateFormatter.parseDate() from https://github.com/kartik-v/php-date-formatter around line 1180 in jquery.datetimepicker.js
a validation is not reliable for the following cases:

  1. date is invalid, but time is partially valid, e.g:
    '2016/04/33 10:13' -> '1899/12/31 10:13'
    '2016/04/33 1' -> '1899/12/31 1:00'
    '2016/04/33 99' -> '1899/12/31 00:00'
    this is because parseDate() ignores invalid date part if time part is present.
  2. date is valid, but time is invalid, e.g:
    '2016/04/05 99:88' -> '2016/04/05 00:00'
    this is because parseDate() doesn't validate time part at all.

Tested with php-date-formatter 1.3.3.

@vzverev78
Copy link
Contributor Author

vzverev78 commented Apr 5, 2016

If using alternative date formatter as recommended in docs: http://xdsoft.net/jqplugins/datetimepicker/#use_other_date_parser
the datetimepicker doesn't detect invalid date because moment() returns non-false object in case of invalid date.
Correct code is:

$.datetimepicker.setDateFormatter({
    parseDate: function (date, format) {
        var d = moment(date, format);
        return d.isValid() ? d.toDate() : false;
    },

    formatDate: function (date, format) {
        return moment(date).format(format);
    }
});

And don't forget to add 'format' into datetimepicker constructor.

vzverev78 added a commit to vzverev78/datetimepicker that referenced this issue Apr 6, 2016
vzverev78 added a commit to vzverev78/datetimepicker that referenced this issue Apr 6, 2016
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

1 participant