∟"yearMonthDuration" Datatype Values and Representations
This section describes the built-in primitive datatype, 'yearMonthDuration' that represents durations of time in units of months in Gregorian calendar. Leading and trailing whitespaces are allowed and trimmed. 'yearMonthDuration' values can be stored as 'integer' values.
If we look closer at the duration seven-property model,
we actually consolidate "duYear", "duMonth", "duDay", "duHour", "duMinute" and "duSecond"
into two properties:
Based on the consolidated duration model of "duSign", "duYearMonth" and "duDayTime",
XSD introduced 2 new built-in datetypes: "yearMonthDuration" and "dayTimeDuration",
so their values can be stored as single interger or decimal number.
Note that there is no easy way to consolidate all of them into a single property,
because number of days in a month is not a constant in Gregorian calendar.
"yearMonthDuration" is a built-in datatype derived from "duration" datatype introduced in XSD 1.1
to represent a duration of time in units of months with these rules:
The value space of "yearMonthDuration" is all possible durations of time in units of months,
by combining the "duYear" and "duDay" properties into days as "integer" values.
The lexical space of "yearMonthDuration" is all possible "yearMonthDuration" values represented in
(duSign)P(duYear)?(duMonth)? pattern.
"duYear" and "duMonth" are both 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 "yearMonthDuration" datatype to declare XML elements:
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
yearMonthDuration_datatype_test.xsd
yearMonthDuration_datatype_test.xml
Error:
Line number: 13
Column number: 62
Message: cvc-datatype-valid.1.2.1: 'P2147483648Y' is not a valid
value for 'yearMonthDuration'. (Value out of "int" range)
Error:
Line number: 13
Column number: 62
Message: cvc-type.3.1.3: The value ' P2147483648Y ' of
element 'YearMonthDuration' is not valid.
Error:
Line number: 14
Column number: 53
Message: cvc-datatype-valid.1.2.1: 'P1D' is not a valid value for
'yearMonthDuration'. (Days not allowed in "yearMonthDuration")
Error:
Line number: 14
Column number: 53
Message: cvc-type.3.1.3: The value ' P1D ' of element
'YearMonthDuration' is not valid.
Error:
Line number: 15
Column number: 58
Message: cvc-datatype-valid.1.2.1: 'PT1H1M1S' is not a valid value
for 'yearMonthDuration'. (Hours, minutes and seconds not allowed)
Error:
Line number: 15
Column number: 58
Message: cvc-type.3.1.3: The value ' PT1H1M1S ' of element
'YearMonthDuration' is not valid.
Failed with errors: 6