Plain luxonDateTime objects provide a boolean .isValid property indicating whether the input date is a valid date. What is a good way to find out if the input date is valid with vue-luxon?
Here's the solution I came up with. this.$luxon() either returns a formatted date or throws an error when the input date is invalid or unparseable. So instead of using an if() condition to test for the .isValid property, I used a try...catch block which tries to parse the input date, and catches the error thrown if the date could not be parsed or is invalid.
The example below uses nested try...catch blocks to demonstrate how it is possible to validate multiple input formats, which is what my code needed to do.
Plain
luxon
DateTime
objects provide a boolean.isValid
property indicating whether the input date is a valid date. What is a good way to find out if the input date is valid withvue-luxon
?Here's the solution I came up with.
this.$luxon()
either returns a formatted date or throws an error when the input date is invalid or unparseable. So instead of using anif()
condition to test for the.isValid
property, I used atry...catch
block which tries to parse the input date, and catches the error thrown if the date could not be parsed or is invalid.The example below uses nested
try...catch
blocks to demonstrate how it is possible to validate multiple input formats, which is what my code needed to do.Is there a better way to accomplish this same goal with
vue-luxon
?