views:

11

answers:

1

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:

  1. Read out both the short and medium date format patterns for the current locale
  2. Remove the slashes from both patterns.
  3. Try to parse the string using both of these modified pattern.
  4. 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! :)

A: 

There's no support for this. dijit.form.DateTextBox doesn't support optional separators or more than one pattern. I suppose you could devise a regular expression based on the data in dojo/cldr (generally undocumented, I know) and use a plain ValidationTextBox with that pattern or even create your own widget... but I can imagine cases where entry text would be ambiguous without the separators.

peller
Okay. I guess I have to do this manually.
ManiSto