Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6238708

DatatypeFactory.newDurationYearMonth doesn't discard milliseconds in result Duration object

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 5.0
    • xml
    • 1.4
    • generic
    • generic

      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

            jsuttorsunw Jeff Suttor (Inactive)
            ydanilev Yury Danilevich (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: