How do I make dojo parse dates without the slashes, while still respecting the current locale? Example:
Dates that must be parseable if locale is:
- en-us
- 12/24/2010
- 12/24/10
- 12242010
- 122410
- da-dk
- 24/12/2010
- 24/12/10
- 24122010
- 241210
Currently dojo only parses the dates containing slashes. The dates without slashes return null when parsed. Currently I only need parsing of these two locales, but I would like to make a generic method, so I can add more locales without changing the parsing. One possibility could be to:
- Read out both the short and medium date format patterns for the current locale
- Remove the slashes from both patterns.
- Try to parse the string using both of these modified pattern.
- Return the first, non-null (if any) result.
Is that the way to go, or am I over complicating things? Another way could be to add the slashes to the string to be parsed, but that seems to be the wrong way around. Help! :)