From: Stephen C. <sco...@jo...> - 2004-11-10 14:59:13
|
Quoting Jaap Reitsma <Jaa...@te...>: > My period string has the format: PT1H7M57S > No days, although days are optional. In fact all fields are optional. > Can I parse this with the period parser? This should parse, so it sounds like a bug to me. > When printing that one with toString, it prints PT1H7M57S, which seems a > bit inconsistent, as it it can't parse what it prints. Not every format that it can print can be parsed, but the standard formats should be parsable. > Relying on the ConverterManager, I tried to create a Duration from the > period. Again out of luck, no duration converter found for type: > org.joda.time.Period. The problem here is that a Period can only be converted to a Duration relative to a start Instant (as months/years/days are variable in length). Two possible code choices are: new Interval(startInstant, period).toDuration(); period.toDurationFrom(startInstant) Stephen > My questions: > - How to specify that fields are optional? > - How to convert my period into a duration? > - What/Where is the difference between the parse format and printing > format? > > Kind regards, > > Jaap |