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

Re: Comparing two dates when one is potentially malfor

Subject: Re: Comparing two dates when one is potentially malformed
From: "Bridger Dyson-Smith bdysonsmith@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 5 Dec 2016 16:11:38 -0000
Re:  Comparing two dates when one is potentially malfor
Hi Wolfgang -

On Mon, Dec 5, 2016 at 3:18 AM, Wolfgang Laun wolfgang.laun@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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 <>)

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.