xsl-list
[Top] [All Lists]

Re: [xsl] Comparing two dates when one is potentially malformed

2016-12-05 10:11:45
Hi Wolfgang -

On Mon, Dec 5, 2016 at 3:18 AM, Wolfgang Laun 
wolfgang(_dot_)laun(_at_)gmail(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

If all the "malformed forms" are due to omitted seconds and if it is only
the date you are interested in, truncate values at the separator 'T' and
compare the date. Even a string comparison would work on the yyyy-mm-dd
formatted values. Or truncate at the length that includes hh:mm and
compare.

Thanks for the response! After getting a better handle on requirements, it
sounds like I don't need to worry about the time values, so this is the
approach I'll use.


-W


Cheers,
Bridger


On 5 December 2016 at 05:03, Bridger Dyson-Smith 
bdysonsmith(_at_)gmail(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

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
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://-list/528976> (by email)


XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/1230532> (by
email <>)

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>