XSD Tutorials - Herong's Tutorial Examples - Version 5.10, by Dr. Herong Yang

"dayTimeDuration" Datatype Values and Representations

This section describes the built-in primitive datatype, 'dayTimeDuration' that represents durations of time in units of seconds in Gregorian calendar. Leading and trailing whitespaces are allowed and trimmed. 'dayTimeDuration' values can be stored as 'decimal' values.

"dayTimeDuration" is a built-in datatype derived from "duration" datatype introduced in XSD 1.1 to represent a duration of time in units of seconds with these rules:

  • The value space of "dayTimeDuration" is all possible durations of time in units of seconds, by converting the "duDay", "duHour", "duMinute" and "duSecond" properties into seconds as "decimal" values.
  • The lexical space of "dayTimeDuration" is all possible "dayTimeDuration" values represented in (duSign)P(duDay)?(T(duHour)?(duMinute)?(duSecond)?)? pattern.
  • "duDay", "duHour", "duMinute" and "duSecond" are all optional. But at least one of them must present.
  • Leading and trailing whitespaces allowed and trimmed.

To verify these rules, I wrote this simple XSD document that uses "dayTimeDuration" datatype to declare XML elements:

<?xml version="1.1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- dayTimeDuration_datatype_test.xsd
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<xs:element name="DayTimeDuration_Datatype_Test">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="DayTimeDuration" type="xs:dayTimeDuration"
         maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

Here is a sample XML document that can be used to test these declarations:

<?xml version="1.1"?>
<!-- dayTimeDuration_datatype_test.xml
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<DayTimeDuration_Datatype_Test>

<!-- 6 valid "DayTimeDuration" elements -->
  <DayTimeDuration>    P0DT0H0M0S    </DayTimeDuration>
  <DayTimeDuration>    P2147483647D    </DayTimeDuration>
  <DayTimeDuration>   -PT2147483647H   </DayTimeDuration>
  <DayTimeDuration>    PT2147483647M    </DayTimeDuration>
  <DayTimeDuration>-PT12345678901234.12345678901234S</DayTimeDuration>
  <DayTimeDuration>
P2147483647DT2147483647H2147483647M123456789012345.123456789012345S
  </DayTimeDuration>

<!-- 3 invalid "DayTimeDuration" elements -->
  <DayTimeDuration>    PT2147483648H    </DayTimeDuration>
  <DayTimeDuration>    P1M    </DayTimeDuration>
  <DayTimeDuration>    PT1S1M    </DayTimeDuration>
</DayTimeDuration_Datatype_Test>

Since "dateTimeStamp" is introduced in XSD 1.1, I need to use my Xsd11SchemaValidator.java program presented earlier in the book to run the test:

c:\Progra~1\Java\jdk1.7.0_07\bin\java 
   -cp ".;c:\local\xerces-2_11_0-xml-schema-1.1-beta\xercesImpl.jar;
   c:\local\xerces-2_11_0-xml-schema-1.1-beta
   \org.eclipse.wst.xml.xpath2.processor_1.1.0.jar"
   Xsd11SchemaValidator 
   dayTimeDuration_datatype_test.xsd dayTimeDuration_datatype_test.xml

Error:
   Line number: 18
   Column number: 59
   Message: cvc-datatype-valid.1.2.1: 'PT2147483648H' is not a valid 
   value for 'dayTimeDuration'. (Value out of "int" range)

Error:
   Line number: 18
   Column number: 59
   Message: cvc-type.3.1.3: The value '    PT2147483648H    ' of 
   element 'DayTimeDuration' is not valid.

Error:
   Line number: 19
   Column number: 49
   Message: cvc-datatype-valid.1.2.1: 'P1M' is not a valid value for 
   'dayTimeDuration'. (Months not allowed)

Error:
   Line number: 19
   Column number: 49
   Message: cvc-type.3.1.3: The value '    P1M    ' of element 
   'DayTimeDuration' is not valid.

Error:
   Line number: 20
   Column number: 52
   Message: cvc-datatype-valid.1.2.1: 'PT1S1M' is not a valid value 
   for 'dayTimeDuration'. (Minutes should be before seconds)

Error:
   Line number: 20
   Column number: 52
   Message: cvc-type.3.1.3: The value '    PT1S1M    ' of element 
   'DayTimeDuration' is not valid.

Failed with errors: 6

Last update: 2013.

Table of Contents

 About This Book

 Introduction to XML Schema

 XML Editor and Schema Processor - XMLPad

 Java API for XML Processing - JAXP

 JAXP - XML Schema (XSD) Validation

 Xerces2 Java Parser - Java API of XML Parsers

 Using Xerces2 Java API

 XML Schema Language - Basics

 Introduction of XSD Built-in Datatypes

 "string" and Its Derived Datatypes

 "decimal" and Its Derived Datatypes

"dateTime" and Its Related Datatypes

  Date/Time Seven-Property Model

 "dateTime" Datatype Values and Representations

 "dateTimeStamp" Datatype Values and Representations

 "date" Datatype Values and Representations

 "time" Datatype Values and Representations

 "gYear", "gMonth" and "gDay" Datatypes

 "gYearMonth" and "gMonthDay" Datatypes

 "duration" Datatype Values and Representations

 "yearMonthDuration" Datatype Values and Representations

"dayTimeDuration" Datatype Values and Representations

 Date, Time and Duration Datatype Summary

 Miscellaneous Built-in Datatypes

 Facets, Constraining Facets and Restriction Datatypes

 "simpleType" - Defining Your Own Simple Datatypes

 Complex Element Declaration

 Identity-Constraints: unique, key and keyref

 Assertion as Custom Validation Rules

 XML Schema Location and Namespace in XML Documents

 Overriding Element Types in XML Documents

 Linking Multiple Schema Documents Together

 Glossary

 References

 PDF Printing Version

"dayTimeDuration" Datatype Values and Representations - Updated in 2014, by Dr. Herong Yang