datejs icon indicating copy to clipboard operation
datejs copied to clipboard

ICU date formats

Open goetas opened this issue 10 years ago • 9 comments

Add support for as many ICU output format options as possible in toString or Format (whichever is appropriate). (edited by abritinthebay)

original issue:

Hi! I'm trying to use datejs to parse some date formats (http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details) is Date.parseExact intended to this aim?

I've read that it supports only ISO... is it true?

goetas avatar Apr 30 '14 09:04 goetas

DateJS parses waaay more than just ISO formats! It's even got some natural language parsing (ie "tomorrow" or "last Thursday", etc).

There doesn't seem anything it couldn't parse there. The way that classes uses output formats is very similar to the toString and Format methods.

ParseExact would be able to not only parse, but validate. In other words it won't parse anything that isn't the format you specify.

Depending on your use case either would work

abritinthebay avatar Apr 30 '14 15:04 abritinthebay

y.M.d - G can not be parsed (using toString), but is a valid ICU format...

goetas avatar Apr 30 '14 20:04 goetas

Ah I see. Yes, some of those are odd formats. Also - to be a little pedantic - it seems you're less concerned with parsing rather than output. Parsing would usually be Date.parse(string) which should cope with most strings output by ICU

However you seem to be specifically wanting string output - in which case some of the forms aren't supported, that's correct. I will add "y" to toString though - doesn't make a lot of sense that that isn't supported.

The others might be better off in format perhaps, as they are more extended formats (like G). Some however won't be supported as they are already taken in other forms (as DateJS is patterned from the PHP date string formatting module originally, which was based on a unix library afaik).

However I will edit this ticket and re-open so I can track support of this formatting convention.

abritinthebay avatar Apr 30 '14 21:04 abritinthebay

Note - it's possible I might create a ICU specific output mode, but we'll see. I'm not convinced of the value as ICU is basically unknown outside of the C++ world. I'll add as many features as possible to the Format module but I'll be keeping primary compatibility with the more common usage formats.

That said - I'll patch y into there right now..

abritinthebay avatar Apr 30 '14 21:04 abritinthebay

I will prefer to have something as toStringIcu and parseExactIcu. I'm not sure that all ICU rules are compatible with ISO.

goetas avatar May 01 '14 11:05 goetas

You have to support also here https://github.com/abritinthebay/datejs/blob/master/src/core/parsing_grammar.js#L116 the single "y" format.

goetas avatar May 01 '14 11:05 goetas

here https://github.com/twitter/twitter-cldr-js, they have implemented the toString that uses ICU format, but they do not offer anything like parseExact.

goetas avatar May 01 '14 11:05 goetas

Yeah, I think the sheer size of that codebase shows that I won't be doing a 100% implementation in DateJS (it's just out of scope) but some support is totally possible. There are some interesting features to the ICU formats that I feel would add valuable extra formatting (like AD/BC etc).

abritinthebay avatar May 02 '14 17:05 abritinthebay

punting to post 1.0 milestone.

abritinthebay avatar Jun 25 '14 20:06 abritinthebay