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.
[1]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3
Regards,
Barend Garvelink
Java Competence Network
Sogeti Nederland B.V.
www.sogeti.nl
Disclaimer:
This message contains information that may be privileged or confidential and is
the property of Sogeti Nederland B.V. or its Group members. It is intended only
for the person to whom it is addressed. If you are not the intended recipient,
you are not authorized to read, print, retain, copy, disseminate, distribute,
or use this message or any part thereof. If you receive this message in error,
please notify the sender immediately and delete all copies of this message.
-------------------------------------------------------------------------
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