amsul / pickadate.js

The mobile-friendly, responsive, and lightweight jQuery date & time input picker.
http://amsul.ca/pickadate.js
MIT License
7.7k stars 1.02k forks source link

Issue on disabling dates, overlapping months, wrong date being selected #1179

Closed MichaelBelgium closed 5 years ago

MichaelBelgium commented 5 years ago

Using laravel 5.8 and having a min and max in pickadate options, it's selecting the wrong date.

I got this in javascript:

$('#date').pickadate({
    disable: [2],
    min: [2019,6,29],
    max: [2019,7,5]
});

It disabling every tuesday and you can max select a week from now. The dates are generated dynamicly (obviously). So if you would visit my page tomorrow it would say

$('#date').pickadate({
    disable: [2],
    min: [2019,6,30],
    max: [2019,7,6]
});

Going back to the first example, it results to this:

image

First thing first: the month selected is july wich is wrong (juli = dutch for july). Tomorrow, 29th is still june. Which then results in wrong date being selected, the date that get posted through is 2019/07/29, which should be 2019/06/29

<input type="hidden" name="date_submit" value="2019/07/29">

Anyone encountered this before? I'm using version 3.6.3 from npm. Is this an issue due the localization or the core?

DanielRuf commented 5 years ago

Hi @MichaelBelgium,

your issue is about multiple single issues. The month is 0-indexed so 6 is July.

DanielRuf commented 5 years ago

See the following note in the docs:

NOTE: months in a JavaScript Date object are zero-indexed. Meaning, new Date(2016, 3, 20) is 20 April, 2016.

To stay consistent with this, whenever an integer is used in reference to a month, pickadate treats it as zero-indexed. Dates as strings are still parsed as expected.

https://amsul.ca/pickadate.js/date/

Can you also provide a small codepen which reproduces your issues?

MichaelBelgium commented 5 years ago

Ooh okay, that solves it.

your issue is about multiple single issues.

My intention was to only post about the wrong date being selected. But it all seemed so confusing to me at first

Here's a pen

DanielRuf commented 5 years ago

So is your initial issue and question solved with this?

If this is the case, please close the issue