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

parsing dates

James Cummings james+xquery at blushingbunny.net
Tue Oct 6 16:34:35 PDT 2009


  parsing dates
On Tue, Oct 6, 2009 at 14:44, David Sewell <http://x-query.com/mailman/listinfo/talk> wrote:
> On Mon, 5 Oct 2009, Joe Wicentowski wrote:
>
>> As far as your specific question, you could run a series of "if ($date
>> castable as ...) then ... else" statements on the following datatypes:
> typeswitch tests for node kinds, not data types, so the "if castable"
> approach is probably the way to go (barring the custom data type
> solution that Michael mentioned).

Thanks Joe, Mike, and David,

I think you are right that the "if castable as" approach will work the
best. Mike's suggestion (while perhaps more reliable) is probably
overkill.  I don't actually care to validate the dates as a date,
since if someone is putting in funny non-dates in this case, then they
probably deserve the error message they'll get.  The files are a
historical diary and I just want to give users (well, and my
processing) the option of looking at it by day, by month, or by year
through a simple change in a hackable human-readable URL. All the real
date/@when in the files are YYYY-MM-DD but want to let them do
/diary/1788-04-07.html (or .xml) and get that one day's entry or
/diary/1788-04.html to get the month or /diary/1788.html to get the
year.  Obviously in 99% of the time the urls will be generated from
some link they are clicking on but it gives me an easy way to move
from day to month to year if desired.

I suppose another way would be not to treat these as dates at all, but
in canonicalizing the data before loading it into eXist, I could give
unique @xml:ids to each day, month and year, that were in the form of
somethingYYYY on the enclosing element for the year's entries,
somethingYYYY-MM for the element enclosing a month, and
somethingYYYY-MM-DD for the element enclosing a day.  That way when
then ask for /diary/YYYY-MM-DD I would just go get the element with
somethingYYYY-MM-DD as an @xml:id.  I guess that the drawbacks of that
are that I can't really do an date-arithmetic, but that said at this
stage I'm not sure I need to. I was just assuming I should be doing it
by date (rather than ID) because the whole work is date oriented.

Thanks for the help, as I'm now working feverishly on this I'm sure
I'll be asking for help again soon! ;-)

-James


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.