http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeParser.html
Also, for making more efficient pattern based parsers, look at the source for ISODateTimeFormat. You can build up complex parsers using DateTimeFormatterBuilder that don't have to check all possible formats from scratch.
On 9/26/06, Garvelink, Barend <[EMAIL PROTECTED]> wrote:
Hi,
For my current job, I had to conjure up a little method that parses the
HTTP Date format, as defined in [1]. HTTP fixed dates can come in three
different flavours, and the standard requires that you can handle all
three. I ended up defining both a DateTimeFormatter and a regex Pattern
for each format, to avoid using exceptions for flow control with just
the DateTimeFormatters.
In other words:
if (pattern1.matches ) {
formatter1.parse();
}
else if (pattern2.matches) {
//etc
Aside from the question of whether or not I tackled the problem in the
best possible way, it occured to me that it is a reasonably common case
to want to know whether an input is parseable. I think it would be quite
useful to have a boolean brother for each of the parse...() methods on
DateTimeFormatter interface, that returns true if the associated parse
method would run without throwing an IllegalArgumentException.
In the above scenario, this would of course imply parsing the input
string *twice* for the matching pattern, once to get a boolean, and once
more to get a DateTime for input String. Ideally, both can be done in
one go. Since we don't have output params in Java, the most likely
alternative would be an overload to the existing parse methods that
returns null instead of throwing IllegalArgumentException.
Lastly, parsing HTTP dates *might* (or might not) be a common enough
case to warrant its own little method in a Utils class somewhere.
So what do other people think of this. Good idea / bad idea?
What, exactly, should the method signatures be?
I'd be happy to contribute some spare time to this.
------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________ Joda-interest mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/joda-interest
