When DatatypeFactory creates javax.xml.datatype.Duration object by newDurationYearMonth methods it should discard any superfluous milliseconds as it is written in the javadoc:
Any remaining milliseconds after determining the day, hour, minute and second are discarded.
However newDurationYearMonth creates the same Duration objects like newDuration methods. You can reproduce it by following test code:
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.Duration;
import javax.xml.datatype.DatatypeFactory;
class test {
public static void main(String [] args) throws Exception {
DatatypeFactory factory = null;
try {
factory = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException dce) {
dce.printStackTrace();
}
System.err.println("duration: " + factory.newDurationYearMonth(1200));
System.err.println("duration: " + factory.newDurationYearMonth("P1MT1S"));
}
}
If we run it on JDK5.0-b64 the result is following:
duration: PT1.200S
duration: P1MT1S
In fact according to the specification duration should not contain seconds field. So the result should be like following:
duration: PT0S
duration: P1M
Another way is to throw IllegalArgumentException for newDurationYearMonth(String lexicalRepresentation) factory method since argument should be in "PnYnM" format.
###@###.### 2005-03-10 09:54:38 GMT
Any remaining milliseconds after determining the day, hour, minute and second are discarded.
However newDurationYearMonth creates the same Duration objects like newDuration methods. You can reproduce it by following test code:
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.Duration;
import javax.xml.datatype.DatatypeFactory;
class test {
public static void main(String [] args) throws Exception {
DatatypeFactory factory = null;
try {
factory = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException dce) {
dce.printStackTrace();
}
System.err.println("duration: " + factory.newDurationYearMonth(1200));
System.err.println("duration: " + factory.newDurationYearMonth("P1MT1S"));
}
}
If we run it on JDK5.0-b64 the result is following:
duration: PT1.200S
duration: P1MT1S
In fact according to the specification duration should not contain seconds field. So the result should be like following:
duration: PT0S
duration: P1M
Another way is to throw IllegalArgumentException for newDurationYearMonth(String lexicalRepresentation) factory method since argument should be in "PnYnM" format.
###@###.### 2005-03-10 09:54:38 GMT