[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
ANN: Portable Data Component -- time interval (start/end orstart/duration)
- From: "Costello, Roger L." <costello@mitre.org>
- To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
- Date: Sat, 23 Apr 2011 10:36:02 -0400
Hi Folks,
This is an extension of the start/end portable data component.
A time interval may be expressed using either of these:
- start and end values, or
- start and duration values.
Here are examples using start/duration.
Example #1
The class starts on May 3, 2011 at 8am and runs for 8 hours:
<class>
<start>2011-05-03T08:00:00</start>
<duration>PT8H</duration>
</class>
Example #2
My vacation begins June 22, 2011 and is for 3 days:
<vacation>
<start>2011-06-22</start>
<duration>P3D</duration>
</vacation>
The constraints on the start/end values are those described earlier.
There is one constraint on the start/duration values: the duration must not be a negative value.
Determining that duration is not a negative value is not straightforward. One would think that this XPath expression would do the job:
xs:duration(duration) gt xs:duration("P0Y")
However, that is not correct. It will generate this error:
xs:duration is not an ordered type
Instead, what is required is to treat duration as a string and check that the string starts with the letter 'P' (i.e., not the letter '-'):
starts-with(duration, 'P')
Here is the time-interval portable data component:
<xs:complexType name="time-interval">
<xs:sequence>
<xs:element name="start">
<xs:simpleType>
<xs:union memberTypes="xs:date xs:time
xs:dateTime" />
</xs:simpleType>
</xs:element>
<xs:choice>
<xs:element name="end" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="xs:date xs:time
xs:dateTime" />
</xs:simpleType>
</xs:element>
<xs:element name="duration" type="xs:duration" />
</xs:choice>
</xs:sequence>
<xs:assert test="if (exists(end)) then
if (start castable as xs:dateTime) then
xs:dateTime(end) gt xs:dateTime(start)
else if (start castable as xs:date) then
xs:date(end) gt xs:date(start)
else if (start castable as xs:time) then
xs:time(end) gt xs:time(start)
else true()
else if (exists(duration)) then
starts-with(duration, 'P')
else true()" />
</xs:complexType>
A summary of all our discussions on Portable Data Components may be found here:
http://www.xfront.com/xml-schema-1-1/best-practice/portable-data-components/Portable-Data-Components.pdf
/Roger
[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]