Domanda

I'm trying to use Joda to support all XACML data times but am having trouble getting it to parse duration from strings like "P50DT4H4M3S". I suspect the problem is ISO and W3C parted ways at some point and Joda supports the ISO path.

In any event, is there an easy way to bridge the gap. I'd like to avoid building my own parser if possible.

I'm aware of javax.xml types, which seems to do what I need, except its based on GregorianCalendar which I'd hoped to avoid by using Joda.

È stato utile?

Soluzione

P50DT4H4M3S is a Period in Joda-Time terminology, and can be parsed using PeriodFormatter. There are standard parsers in ISOPeriodFormat.

Altri suggerimenti

Something like this:

PeriodFormatter formatter = ISOPeriodFormat.standard();
Period period = asd.parsePeriod(periodString);
Duration duration = dsa.toStandardDuration();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top