Joda-Time doe snot support this XML encoding with a leading sign. Its not a standard ISO-8601 format AFAICT. Instead, we use P-120D. Stephen
On 19 June 2013 15:31, Gemmill, Craig <craig.gemm...@tridium.com> wrote: > Hi all- > > > > I’m new to using Joda-time, but I have a question about using Period with > negative times. According to the XML Schema xs:duration datatype, and as > far as I can tell, the ISO8601 format, a negative duration would be > expressed with a leading minus sign. For example, minus 120 days would be > “–P120D”. However, I tried a quick ‘roundtrip’ test using > org.joda.time.Period and org.joda.time.format.ISOPeriodFormat, and this > doesn’t seem to work: > > > > import org.joda.time.Period; > > import org.joda.time.format.ISOPeriodFormat; > > > > public class PeriodTester > > { > > public static void main(String[] args) > > { > > Period p = new Period(-8); > > String s = ISOPeriodFormat.standard().print(p); > > Period p1 = ISOPeriodFormat.standard().parsePeriod(s); > > System.out.println("p:"+p+"; ->s:"+s+"; ->p1:"+p1); > > } > > } > > > > I would expect this to output: > > p:-PT0.008S; ->s:-PT0.008S; ->p1:-PT0.008S > > > > But instead I get > > p:PT-0.008S; ->s:PT-0.008S; ->p1:PT0.008S > > > > So this is not able to survive an encode/decode. It appears that the > encoder is not putting the minus sign in the right place, but the decoder is > expecting a leading sign? > > > > Is there a better way to encode the Period so that it uses a leading minus > sign? > > > > Thanks! > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > _______________________________________________ > Joda-interest mailing list > Joda-interest@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/joda-interest > ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev _______________________________________________ Joda-interest mailing list Joda-interest@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/joda-interest