Bradjcox
Bradjcox

Reputation: 1509

JodaTime for XML Schema/XACML Duration types

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.

Upvotes: 1

Views: 948

Answers (2)

Petras Butkevicius
Petras Butkevicius

Reputation: 93

Something like this:

PeriodFormatter formatter = ISOPeriodFormat.standard();
Period period = asd.parsePeriod(periodString);
Duration duration = dsa.toStandardDuration();

Upvotes: 0

JodaStephen
JodaStephen

Reputation: 63465

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

Upvotes: 3

Related Questions