• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SimpleDateFormat not parsing valid RFC822 date?

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Line 3 fails even though I think 2009-08-07T15:00:00.000Z is a valid timestamp. (See http://tools.ietf.org/html/rfc3339#section-5.8) Am I doing something wrong, or is this a bug in SimpleDateFormat?
 
Max Rahder
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It also doesn't support dates whose time zone adjust is in the format -08:00, which is also part of RFC822.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The API documentation for SimpleDateFormat says exactly what parsing will accept as a time-zone when the "Z" character is used in the format string. I don't see where it says it will accept a "Z" as a time-zone. And it doesn't mention accepting colons either. So I would say the class is working according to its published specifications.
 
Max Rahder
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It specifically says that Z is for an RFC822 time zone:
http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html
"Z Time zone RFC 822 time zone -0800"

Their sample is in the offset format, sans the colon. "Z" as a suffix for Zulu time is certainly part of RFC822. I guess Sun's implementation is non-standard, in that it doesn't appear to comply with RFC822. I wonder what standard they were coding against, or what feeds can use their format? The data I'm reading complies with the published RFC822 format, so it's a bummer I apparently can't use SimpleDateFormat to parse it.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your gripe is that the documentation says "RFC822 time zone" but doesn't provide a full implementation of RFC822, then you're absolutely correct. But I would expect you aren't the first person to run into this... have you googled for third-party classes which might work better?
 
Max Rahder
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Their lack of support for the colon is non-standard too. I did Google for other parsers, but didn't find any within the time span of my patience. Apache Commons has one, but it only formats -- it doesn't parse. Oh well.
 
Max Rahder
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:If your gripe is that the documentation says "RFC822 time zone" but doesn't provide a full implementation of RFC822, then you're absolutely correct. But I would expect you aren't the first person to run into this... have you googled for third-party classes which might work better?



By the way, I'm not trying to gripe -- I'm just confused by the behavior and thought I might have made a mistake in my parse pattern, or misunderstood the documentation. I'm still not sure if their documentation is wrong, or their implementation. Is there some place on the Sun site where I can document this apparent inconsistency?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the place to report bugs: http://bugs.sun.com/

I wouldn't be at all surprised to find that your issue is already in that database, though. Sun doesn't seem to be very proactive at fixing small things like that.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The time / date / calendar APIs in Java are unfortunately not great on some points, and that's why Joda Time is a very popular open-source library to deal with time and date values better.

There's an initiative, JSR-310, for a new standard time / date / calendar API for Java, which is based on Joda Time - so something like Joda Time will probably become standard in a future version of Java.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what I've seen and read, Java 7 is supposed to implement that JSR. However I had a quick look at the Joda API and their DateTimeFormat class doesn't seem to support all of RFC 822 either.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic