Menu

#69 Provide a parser for partials

open
nobody
Joda-Time (26)
5
2014-08-18
2011-04-08
No

Writing a ReadablePartial, e.g. Month and Day but without Year results in: --03-18
Parsing this String with: ISODateTimeFormat.date().parseDateTime("--03-18");
fails with "Invalid Format".

Ok, the formatter is supposed to construct a DateTime object which is a Instant, not a Partial.
However it would be great to parse into a Partial.

Alternatively, how would I serialize and deserialize a partial into a string?

Thank you for the great library.

Discussion

  • Daniel Hirscher

    Daniel Hirscher - 2011-04-11

    The forFields() method does not work for me:

    • I do not know which of the fields are missing before parsing, e.g.: "--03-18" or "2011-01--" or "--04--" is possible in my case
    • forFields() does not return a partial, so parsing "--03-18" results in a DateTime with 1970 as year

    I think I will write my own formatter and parser.

    The use case is to handle partial birthday dates. For some people I do not know the year, for others not the exact day of the month. So partials are a good choice for me, since birthdays do not need a time zone either.

     
  • RubyTuesdayDONO

    RubyTuesdayDONO - 2012-03-08

    i'm not sure how to upvote issues on sourceforge, but count this as my vote!

    i have a compelling use case for parsing Partials from Strings and would love to see this implemented in Joda-time. for now, i'll try to roll my own. thanks for maintaining this great library!

    http://stackoverflow.com/questions/9611002/
    http://stackoverflow.com/questions/5068626/

     

Log in to post a comment.

MongoDB Logo MongoDB