> >The string I receive from a service is formatted as "3 PM CST 18 MAR
> >06". Time zones are relevant, and I do have an offset available as
> >"-6". However, according to the documentation I think I should be
> >able to parse the supplied string as
> > DateTimeFormat.forPattern("hh aa zzz dd MMM yy")
> >Inevitibly, I get a :
> >java.lang.IllegalArgumentException: Invalid format: "3 PM CST 18 MAR
> >06" is malformed at "CST 18 MAR 06"
> The reason for this is that 'CST' is a short format time zone name.
> These are unclear and ambiguous hence we don't parse them.
I absolutely understand, especially with CST and other truly ambiguous
TZ shortnames.
> It is fustrating however to have Joda-Time unable to do something the
> JDK can so maybe we should look at changing this somehow.
Maybe there could be some sort of switch for following whatever the
running JDK's format is. It would still be ambiguous, but it would
parse
> In the meantime, you can:
> a) Use SimpleDateFormat :-(
This seems the simplest way. Took about 30 seconds to implement. My
app requires no TZs outside the US, so I can reasonably expect this to
work for me. I'll just have to build one every time I parse, for
threading reasons.
> b) Split the input yourself and parse the timezone yourself
This was what I started to do, before I went back and tried to parse
with SimpleDateFormat. The result wasn't really worth the effort.
> c) Implement the Joda-Time DateTimeParser interface yourself to match
> 'CST' into a proper DateTimeZone, and then use DateTimeFormatterBuilder
> to create a combined parser using patterns and your implementation thus
> creating a full parser.
This seems like duplicating the effort of the JDKs version. The
results would still be ambiguous, although I supposed I could supply a
means for choosing what a particular shortname meant.
I think, for my purposes at present, using SimpleDateFormat to get a
Date that I then use to generate a DateTime is the way to go. Since
there's a 0% chance of my service producing anything that's not
ambiguous, I think this is a perfectly reasonable solution.
Thanks for a quick response, Stephen, and thanks again for solving my
date time issues without me having to write custom classes to do it.
:)
--
"My friends tell me I have an intimacy problem. But they don't really
know me." -- Garry Shandling
Anyone who has the power to make you believe absurdities has the power
to make you commit injustices. -- Voltaire
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest