datejs
datejs copied to clipboard
ICU date formats
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?
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
y.M.d - G
can not be parsed (using toString
), but is a valid ICU format...
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.
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..
I will prefer to have something as toStringIcu
and parseExactIcu
. I'm not sure that all ICU rules are compatible with ISO.
You have to support also here https://github.com/abritinthebay/datejs/blob/master/src/core/parsing_grammar.js#L116 the single "y" format.
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
.
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).
punting to post 1.0 milestone.