Trying to get the text parsing to work, but when I enter in a date thats ambiguous "01/02/2017" could be 1st of February or 2nd of January depending on locale.
I'm seeing an issue where sometimes the order of which they appear are reversed, meaning sometimes the dates values are incorrect by at least a month.
Issue appears on the docs site too. https://vcalendar.netlify.com/datepicker.
Edit: I'm also on 0.5.3
The returned date is date.toLocaleDateString() so it depends to your browser local configuration.
But you can override this using available methods:
dateFormatter(date) {
return date.toLocaleDateString()
},
dateParser(text) {
new Date(Date.parse(text))
}
Yes, you can provide your own formatter and parser via the date-parser and date-formatter props. The code that @kl3sk used is the default implementation, btw.
I think the problem here is that Date.parse does not behave consistently across browsers for different locales. Perhaps the best solution here would be to import moment.js into your project and use it's localization methods.
I could include moment within the package itself, but it would just be getting used for date parsing, which seems like a bit overkill. Either way, I will include better tutorials in the docs for working with different locales.
@nathanreyes About moment.js, i don't think you should package with it, but maybe show example on how to use your component with.
Edit: MDN date.parse
Thanks @kl3sk @nathanreyes , youre right and I managed to pass my own custom parse/format functions from moment. And I agree with you, not everyone needs moment.js . Its a shame that locale behaviours between browsers is so fragmented.
Most helpful comment
Thanks @kl3sk @nathanreyes , youre right and I managed to pass my own custom parse/format functions from moment. And I agree with you, not everyone needs moment.js . Its a shame that locale behaviours between browsers is so fragmented.