W3C home > Mailing lists > Public > xmlschema-dev@w3.org > January 2003

Re: date & time pattern change

From: Avin Patel <vze49rz3@verizon.net>
Date: Thu, 2 Jan 2003 13:50:59 -0500
Message-ID: <00c601c2b28f$e405fba0$643a42d1@Avin>
To: "xmlschema" <xmlschema-dev@w3.org>

Hi All,
"pattern" constraint is applicable on "date"/ "time" type.
Can any one please provide me sample, how it can be applicable.
I guess "pattern" restriction on "data"/"time" is confusing. You real can't
apply pattern restriction on data/time type.

Thank you,
Avin Patel


----- Original Message -----
From: "Jeni Tennison" <jeni@jenitennison.com>
To: "Avin Patel" <vze49rz3@verizon.net>
Cc: "xmlschema" <xmlschema-dev@w3.org>
Sent: Sunday, December 29, 2002 7:40 AM
Subject: Re: date & time pattern change


Hi Avin,

> How can change the inbuilt date & time pattern, I.a.
> date has the pattern CCYY-MM-DD, I want to change this pattern to
CCYYMMDD.

You cannot change the legal lexical representations of the primitive
types. For example, you can't make a schema validator recognise "1,2"
as the decimal number 1.2 or recognise "20021229" as 2002-12-29.

If you want your markup language to include dates in the form CCYYMMDD
then you have to create a new type as a restriction of xs:token or
perhaps xs:integer:

<xs:simpleType name="MyDate">
  <xs:restriction base="xs:token">
    <xs:pattern value="[0-9]{4}[01][0-9][0-3][0-9]" />
  </xs:restriction>
</xs:simpleType>

Note that the above allows some dates that shouldn't be allowed, such
as 20020037 or 20030229; you can refine the regular expression to
catch some of these but not all. In addition, if you define your dates
in this format you can't use the facets like min/maxIn/Exclusive to
constrain them.

In general, it's better to use the standard date format CCYY-MM-DD if
you can. If you can't, you're going to need to validate the dates
through some external code, perhaps by performing a transformation on
the data prior to validation to get it into a validatable form.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Thursday, 2 January 2003 13:51:27 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:35 GMT