[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Comparing two dates when one is potentially malformed

Subject: Comparing two dates when one is potentially malformed
From: "Bridger Dyson-Smith bdysonsmith@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 5 Dec 2016 04:02:55 -0000
 Comparing two dates when one is potentially malformed
Hi all --

I'm wondering about best practices when dealing with potentially malformed
dates. I confess that I haven't worked with dates (xs:date, xs:time,
xs:dateTime) very much and so I'm not sure if I'm thinking about things
correctly.

I have the following input:
    <test>
        <field name="publication_date" type="date">
            <value>2011-12-01T00:00-08:00</value>
        </field>
        <field name="embargo_date" type="date">
            <value>2011-12-01T00:00-08:00</value>
        </field>
        <submission-date>2011-11-17T08:11:17-08:00</submission-date>
        <publication-date>2011-12-01T00:00-08:00</publication-date>
    </test>

And I'd like to do a comparison check on the field[@name='embargo_date'] vs
the output of current-dateTime(). I have the following stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">

    <xsl:output encoding="UTF-8" indent="yes" method="xml"/>


    <xsl:variable name="c-dateTime"
                  select="dateTime(xs:date(format-date(current-date(),
'[Y]-[M,2]-[D,2]')),
                                   xs:time(format-time(current-time(),
'[H]:[m]:[s][Z]')))"/>

  <xsl:template match="/">
      <xsl:variable name="test-dateTime" as="xs:dateTime"
select="test/field[@name='embargo_date']/value"/>

      <result><xsl:value-of select="if ($test-dateTime ge $c-dateTime )
then 'embargo me!' else 'all clear!'"/></result>
    </xsl:template>
</xsl:stylesheet>

I'm using Saxon HE-9.6.0.7 in oXygen 18.1, which gives me a compile time
error of "FORG0001: Invalid dateTime value "2018-12-01T00:00-08:00" (Wrong
delimiter after minute)".

Is the right thing to do here to do some string parsing on the substrings
in the values that I need to check? Is there some other way to convert the
value in field[@name='embargo_date'] into an xs:dateTime?

Thanks for your time and trouble.
Best,
Bridger

Current Thread

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-2013 All Rights Reserved.