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
Custom parsing for dates #653
base: master
Are you sure you want to change the base?
Custom parsing for dates #653
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great solution!
I've searched for javascript string parsing solutions that could work with a format string, but it can become tricky.
I think this solution should be merged quite rapidly since users who aren't using US dates, currently face a major bug with the typeable datepicker feature.
Allowing developers to use their own parser, should cover most of the cases, especially when predictable date formats are used.
👍
src/components/DateInput.vue
Outdated
@@ -118,10 +119,11 @@ export default { | |||
} | |||
|
|||
if (this.typeable) { | |||
const typedDate = Date.parse(this.input.value) | |||
const fn = this.parse || Date.parse | |||
const typedDate = fn(this.input.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest your replace line 122-123 with this:
const parsed = this.parse(this.input.value)
if (!isNaN(typedDate)) { | ||
this.typedDate = this.input.value | ||
this.$emit('typedDate', new Date(this.typedDate)) | ||
this.$emit('typedDate', new Date(typedDate)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest your replace line 126 with this:
this.$emit('typedDate', parsed)
src/components/DateInput.vue
Outdated
@@ -130,7 +132,8 @@ export default { | |||
* called once the input is blurred | |||
*/ | |||
inputBlurred () { | |||
if (this.typeable && isNaN(Date.parse(this.input.value))) { | |||
const fn = this.parse || Date.parse | |||
if (this.typeable && isNaN(fn(this.input.value))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest your replace line 135-136 with this:
if (this.typeable && isNaN(this.parse(this.input.value))) {
@@ -118,6 +119,7 @@ export default { | |||
type: [String, Function], | |||
default: 'dd MMM yyyy' | |||
}, | |||
parse: Function, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest you replace line 122 with this:
parse: {
type: Function,
default: v => new Date(v),
}
@SylannBin thanks for the code review; I applied your suggestions (almost entirelly, Ijust moved the default to DateInput instead of Datepicker), |
OK I just spent an hour debugging this, only to arrive at the same solution (we need a custom parsing function). Any chances this can get merged (or reasons not to)? |
Hello ! Also facing this problem using this lib, is it possible to merge ? |
This feature not only solves a bunch of potential parsing issues but it also enables new use cases out of the box, such as:
Hopefully this gets merged soon. |
First of all, thanks @charliekassel for all your work on this. It's awesome! I think this pr could close a huge amount of issues. Just for example:
The equivalent pr for delegating formatting dates was merged the same day it was opened! Also, I would choose this over #536 because it lets users choose how the date is parsed, rather than changing the string that get's passed to I just read #679 (comment) and saw you haven't had time to work on this, and are considering co-maintainers, which I think is a great idea! |
Any news on this? |
When is this feature merged? It is urgently needed for different projects. |
Any updates on when/whether this PR will be merged? It blocks development in several projects at the moment, so an update would be very nice ;-) |
Here! also waiting for the merge!!! |
Any news? |
Is there anything that we can do to help this getting merged? |
when this gets merged, we should be able to make things work. charliekassel/vuejs-datepicker#653
This is a possible fix for #597