This section describes the built-in primitive datatype, 'duration' that represents durations of time. Leading and trailing whitespaces are allowed and trimmed. A 'duration' lexical representation roughly follows this format: PiYiMiDTiHiMdS.
Similar to the data/time seven-property model,
XSD 1.1 uses a duration seven-property model to represent a duration of time in the Gregorian calendar system.
This model is closely related to "ISO 8601 - Data elements and interchange formats" standard.
In this model, any duration of time can be represented with a set of 6 values named as:
"duSign" - A positive "int" value of 1 or -1 representing the sign of the duration.
"duYear" - A positive "int" value representing number of years in the duration.
"duMonth" - A positive "int" value representing number of months in the duration.
"duDay" - A positive "int" value representing number of days in the duration.
"duHour" - A positive "int" value representing number of hours in the duration.
"duMinute" - A positive "int" value representing number of minutes in the duration.
"duSecond" - A positive "decimal" value representing number of seconds and fractions of a second of in the duration.
Each property in the seven-property model has its own lexical space:
"duSign" lexical space is blank or "-". "+" is not allowed.
"duYear" lexical space is all "duYear" values expressed in "int" lexical presentations followed by "Y".
"duMonth" lexical space is all "duMonth" values expressed in "int" lexical presentations followed by "M".
"duDay" lexical space is all "duDay" values expressed in "int" lexical presentations followed by "D".
"duHour" lexical space is all "duHour" values expressed in "int" lexical presentations followed by "H".
"duMinute" lexical space is all "duMinute" values expressed in "int" lexical presentations followed by "M".
"duSecond" lexical space is all "duSecond" values expressed in "decimal" lexical presentations followed by "S".
With this duration seven-property model, the "duration" built-in datatype
can be easily described as below.
"duration" is a built-in datatype that uses the duration seven-property model
to represent a duration of time with these rules:
The value space of "duration" is all possible durations of time in the Gregorian calendar.
The lexical space of "duration" is all possible "duration" values represented in
(duSign)P(duYear)?(duMonth)?(duDay)?(T(duHour)?(duMinute)?(duSecond)?)? pattern.
A "duration" lexical representation roughly follows this format: PiYiMiDTiHiMdS.
"duYear", "duMonth", "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 "time" datatype to declare XML elements:
When validating this XML document with my XsdSchemaValidator.java program presented earlier in the book,
I get 5 groups of errors for 5 invalid XML elements:
c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator
duration_datatype_test.xsd duration_datatype_test.xml
Error:
Line number: 19
Column number: 44
Message: cvc-datatype-valid.1.2.1: 'P2147483648Y' is not a valid
value for 'duration'. (Value is out of "int" range)
Error:
Line number: 19
Column number: 44
Message: cvc-type.3.1.3: The value ' P2147483648Y ' of
element 'Duration' is not valid.
Error:
Line number: 20
Column number: 44
Message: cvc-datatype-valid.1.2.1: 'P2147483648D' is not a valid
value for 'duration'. (Value is out of "int" range)
Error:
Line number: 20
Column number: 44
Message: cvc-type.3.1.3: The value ' P2147483648D ' of
element 'Duration' is not valid.
Error:
Line number: 21
Column number: 45
Message: cvc-datatype-valid.1.2.1: 'PT2147483648H' is not a valid
value for 'duration'. (Value is out of "int" range)
Error:
Line number: 21
Column number: 45
Message: cvc-type.3.1.3: The value ' PT2147483648H ' of
element 'Duration' is not valid.
Error:
Line number: 22
Column number: 39
Message: cvc-datatype-valid.1.2.1: 'P1D1M1Y' is not a valid value
for 'duration'. (Wrong sequence)
Error:
Line number: 22
Column number: 39
Message: cvc-type.3.1.3: The value ' P1D1M1Y ' of element
'Duration' is not valid.
Error:
Line number: 23
Column number: 39
Message: cvc-datatype-valid.1.2.1: 'P1H1M1S' is not a valid value
for 'duration'. (Missing "T")
Error:
Line number: 23
Column number: 39
Message: cvc-type.3.1.3: The value ' P1H1M1S ' of element
'Duration' is not valid.
Failed with errors: 10