[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

parsing dates

Joe Wicentowski joewiz at gmail.com
Mon Oct 5 21:16:57 PDT 2009


  parsing dates
James,

I've encountered the same issue with dates in TEI documents.  What
follows are some thoughts/suggestions about using TEI dates in eXist.

I think the issue is The TEI Guidelines allows/encourages one to mix
date datatypes, thereby conflating data with precision in dates
(http://www.tei-c.org/release/doc/tei-p5-doc/en/html/CO.html#CONADA):

------
"Partial dates or times (e.g. 1990, September 1990, twelvish) can be
expressed in the when attribute by simply omitting a part of the value
supplied. Imprecise dates or times (for example early August, some
time after ten and before twelve) may be expressed as date or time
ranges...  The @when attribute always supplies a normalized
representation of the date given as content of the date element. The
format used should be a valid W3C schema datatype. Some typical
examples follow:

* <date when="2001">The year 2001</date>
* <date when="2001-09">September 2001</date>
* <date when="2001-09-11">11 Sept 01</date>
* <date when="--09-11">9/11</date>
* <date when="--09">September</date>
* <date when="---11">Eleventh of the month</date>
* <time when="08:48:00">8:48</time>
* <date when="2001-09-11T12:48:00">Sept 11th, 12 minutes before 9 am</date>

Note in the last example the use of a normalized representation for
the date string which includes a time: this example could thus equally
well be tagged using the time element.
The following examples demonstrate the use of the date element to mark
a period of time:
* <p>Those five years — <date from="1918" to="1923">1918 to
1923</date> — had been, he suspected, somehow very important.</p>"
-----

If you mix 2+ date datatypes, you will encounter some difficulties
when doing what you asked about.  Setting range indexes in eXist is
impossible if you mix datatypes, as far as I know.  I think we might
encode TEI texts more effectively to make processing easier by (1)
either using a consistent datatype or (2) replacing the generic @when
with a new way of encoding which implies the datatype.

As far as your specific question, you could run a series of "if ($date
castable as ...) then ... else" statements on the following datatypes:

* date
* gYear
* gMonth
* gDay
* gYearMonth
* gMonthDay
* time
* dateTime

As an alternative to conditional expressions, I'm not sure if
typeswitch would work for this?

- Joe



On Mon, Oct 5, 2009 at 7:05 PM, James Cummings
<http://x-query.com/mailman/listinfo/talk> wrote:
> Hi there,
>
> I've a silly question about the best way to parse dates.  I'm passing
> a parameter (in eXist) that is part of the URL for an xquery and I
> want to separate it into its individual parts of year month and day. I
> could test the string and do substring-before and after and such, or
> create my own function, but it seemed better practice to use the
> functions like year-from-date and month-from-date.  So I tried:
>
> let $date := request:get-parameter("date", ("1789-01-01")) cast as xs:date
> let $year := fn:year-from-date($date)
> let $month := fn:month-from-date($date)
> let $day := fn:day-from-date($date)
>
> which works fine when the date is YYYY-MM-DD.  But what I want to
> achieve is being able to handle YYYY-MM-DD, YYYY-MM or just YYYY.  The
> last two give me an error of "xs:date must not have hour, minute or
> second fields set" (erm... which it doesn't, which is why I'm
> confused). I'm happy for $month and $day to be empty if they don't
> exist.
>
> I'm sure it is something terribly obvious with the datatype.  Should I
> just be breaking it down to its component parts myself?  It just
> seemed like I was reinventing the wheel.
>
> Thanks for any suggestions.
>
> -James
> _______________________________________________
> http://x-query.com/mailman/listinfo/talk
> http://x-query.com/mailman/listinfo/talk
>



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.