Closed szahn closed 6 years ago
Globalize throws exceptions on developer errors such as API misuse (e.g., invalid argument type). For values that can't be parsed on runtime, the principle is similar to JavaScript functions such as parseInt()
that returns the parsed value or NaN
.
Having said that, we could return additional information, feel free to suggest how this could be made.
Parser will always work for formatted values, so one way to see how input should look like is to format it, e.g.:
Globalize('en').dateFormatter({skeleton: "yMdhms"})(new Date());
// > '4/12/2018, 10:47:53 AM'
It's not a goal of the parser to parse any kind of input, but to be an inverse operation for the formatter. It's therefore better to use parser on an assisted UI such as https://github.com/rxaviers/react-date-input (that uses format to parts to generate the UI).
I'm closing this since it's not an issue. I can re-open if we figure out any action item that could be done from this thread. Thanks!
This isn't very helpful. I still don't know why that value can't be parsed. From your example above, it seems like the only reason the parsing failed was because a comma was missing between the date and time. Why is the parsing so brittle? More examples of correctly parsing date and time using skeletons would be good, at least explain that a delimiter other than a space is required between date and time to be parsed together as one. I'd rather use MomentJS which automatically parses date time strings.
This isn't very helpful. I still don't why that value can't be parsed
Missing comma
More examples of correctly parsing date and time using skeletons would be good
You could run node and format any skeleton to check the output https://github.com/globalizejs/globalize/#getting-started
I'd rather use MomentJS which automatically parses date time strings.
It's a great library, except for i18n, it doesn't follow CLDR.
A desired behavior would be to throw an exception or return an error result describing why the date time could not be parsed given the skeleton.