Date Format?

Garrett Smith dhtmlkitchen at gmail.com
Sun Apr 20 18:43:42 PDT 2008


2008/4/17 Adam Peller <apeller at us.ibm.com>:
>
>
> Garrett wrote:
> >
> > Properly formatting dates, solution (1), in ES is a lot of work.
> >
>
> Indeed it is.

I can see you've invested considerable time and effort into this problem.

> A couple of Javascript toolkits have taken a crack at this
> problem and provide pluggable, reusable solutions you may want to look at
> (e.g. Dojo's dojo.date.format and datejs available from Google code) There
> are several facets to this problem. First there is the parsing and
> formatting logic, basically string and regexp operations which are not
> unreasonable to delegate to a toolkit. Another is maintaining the large
> translation tables needed to provide this function (communities like the one
> in unicode.org/cldr have taken this on in open source -- there's no reason
> why you should have to build your own translations).

Where'd dojo get the CLDR conversion to JSON?

> Then there is the
> mechanism to embed and load the appropriate resources. Note that this is
> essentially a package loading problem which is not unique to Dates, and Dojo
> leverages its package loader to load locale-sensitive information like these
> date formats. I think this part is most challenging to provide in
> Javascript, but appears to be outside the scope of ES4.
>


Why not just use a script tag to load the only the correct locale from
the start by checking Accept-Language?

<script src="DateLocale<%= getLocaleSuffix() %>"></script>

I don't encourage scriptlets; a tag would be better. Just saying for example.

Dojo's date locale requires an object called 'dojo' and a lot of
static methods of that object. Extensively. A project that's already
using dojo could leverage that, but compared to a native strftime,
it's some overhead to get that date formatted.


> The current ES4 Date proposal provides unambiguous ISO formats which should
> encourage better programming practices. That seems like the right place to
> start. Hard-coding mm/dd/yyyy is just as bad as hard-coding English
> strings.

It's a choice, though, and there's plenty of live code on the web that
does that. Not to PIck on Orbitz (cheap tix), but
calendar.clickDate.toSource() they may have other formats that get
picked in the server side code.

Garrett



More information about the Es4-discuss mailing list