[prev in list] [next in list] [prev in thread] [next in thread]
List: xsl-list
Subject: Re: [xsl] Comparing two dates when one is potentially malformed
From: "Bridger Dyson-Smith bdysonsmith () gmail ! com" <xsl-list-service () lists ! mulberrytech
Date: 2016-12-05 16:12:26
Message-ID: 20161205111137.9365 () lists ! mulberrytech ! com
[Download RAW message or body]
Hi Wolfgang -
On Mon, Dec 5, 2016 at 3:18 AM, Wolfgang Laun wolfgang.laun@gmail.com <
xsl-list-service@lists.mulberrytech.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@gmail.com <
> xsl-list-service@lists.mulberrytech.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/651070
or by email: xsl-list-unsub@lists.mulberrytech.com
--~--
[Attachment #3 (text/html)]
<div dir="ltr">Hi Wolfgang - <br><div><div class="gmail_extra"><br><div \
class="gmail_quote">On Mon, Dec 5, 2016 at 3:18 AM, Wolfgang Laun <a \
href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a> <span \
dir="ltr"><<a href="mailto:xsl-list-service@lists.mulberrytech.com" \
target="_blank">xsl-list-service@lists.mulberrytech.com</a>></span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"><div dir="ltr"><div>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. <br><br></div></div></blockquote><div>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.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div>-W \
<br></div><div class="HOEnZb"><div class="h5"><div \
class="gmail_extra"><br></div></div></div></blockquote><div><br></div><div>Cheers,<br></div><div>Bridger<br> \
<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><div \
class="gmail_extra"><div class="gmail_quote">On 5 December 2016 at 05:03, Bridger \
Dyson-Smith <a href="mailto:bdysonsmith@gmail.com" \
target="_blank">bdysonsmith@gmail.com</a> <span dir="ltr"><<a \
href="mailto:xsl-list-service@lists.mulberrytech.com" \
target="_blank">xsl-list-service@lists.<wbr>mulberrytech.com</a>></span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"><div \
dir="ltr"><div><div><div><div><div><div><div><div>Hi all --<br><br></div>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. \
<br><br></div>I have the following input:<br> <test><br> \
<field name="publication_date" type="date"><br> \
<value>2011-12-01T00:00-08:00<<wbr>/value><br> \
</field><br> <field name="embargo_date" \
type="date"><br> \
<value>2011-12-01T00:00-08:00<<wbr>/value><br> \
</field><br> \
<submission-date>2011-11-17T08<wbr>:11:17-08:00</submission-date><br> \
<publication-date>2011-12-01T0<wbr>0:00-08:00</publication-date><br> \
</test><br><br></div>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:<br><br><?xml version="1.0" \
encoding="UTF-8"?><br><xsl:stylesheet xmlns:xsl="<a \
href="http://www.w3.org/1999/XSL/Transform" \
target="_blank">http://www.w3.org/1<wbr>999/XSL/Transform</a>"<br> \
xmlns:xs="<a href="http://www.w3.org/2001/XMLSchema" \
target="_blank">http://www.w3.org/20<wbr>01/XMLSchema</a>"<br> \
exclude-result-prefixes="xs"<br> version="2.0"><br> \
<br> <xsl:output encoding="UTF-8" indent="yes" \
method="xml"/><br> <br> <br> <xsl:variable \
name="c-dateTime"<br> \
select="dateTime(xs:date(forma<wbr>t-date(current-date(), \
'[Y]-[M,2]-[D,2]')),<br> \
xs:time(format-time(current-ti<wbr>me(), '[H]:[m]:[s][Z]')))"/><br> \
<br> <xsl:template match="/"><br> <xsl:variable \
name="test-dateTime" as="xs:dateTime" \
select="test/field[@name='emba<wbr>rgo_date']/value"/><br> \
<br> <result><xsl:value-of select="if ($test-dateTime ge \
$c-dateTime ) then 'embargo me!' else 'all \
clear!'"/></result><br> \
</xsl:template><br></xsl:stylesheet><br><br></div>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)". <br><br></div>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? \
<br><br></div>Thanks for your time and \
trouble.<br></div>Best,<br></div>Bridger<br></div> <div>
<div style="border-top:1px solid \
black;background-color:#dddddd;color:#888888;font-size:smaller;padding:5px;text-align: \
center;font-family:arial,verdana,arial,sans-serif;margin-top:1em;clear:both;margin:auto">
<a href="http://www.mulberrytech.com/xsl/xsl-list" target="_blank">
XSL-List info and archive</a>
<div style="text-align:center">
<a style="color:blue" href="http://-list/528976" target="_blank">EasyUnsubscribe</a>
(<a style="color:blue">by email</a>)
</div>
</div>
</div></blockquote></div><br></div>
<div>
<div style="border-top:1px solid \
black;background-color:#dddddd;color:#888888;font-size:smaller;padding:5px;text-align: \
center;font-family:arial,verdana,arial,sans-serif;margin-top:1em;clear:both;margin:auto">
<a href="http://www.mulberrytech.com/xsl/xsl-list" target="_blank">
XSL-List info and archive</a>
<div style="text-align:center">
<a style="color:blue" href="-list/1230532" target="_blank">EasyUnsubscribe</a>
(<a style="color:blue" href="" target="_blank">by email</a>)
</div>
</div>
</div></div></div></blockquote></div><br></div></div></div>
<div><!-- begin bl.html.trailer -->
<div style="border-top:1px solid black; background-color: #dddddd;
color: #888888; font-size: smaller; padding: 5px; text-align: center;
font-family: arial,verdana,arial,sans-serif; margin-top:1em; clear:
both; margin: auto">
<a href="http://www.mulberrytech.com/xsl/xsl-list">
XSL-List info and archive</a>
<div style="text-align:center;">
<a style="color: blue;"
href="http://lists.mulberrytech.com/unsub/xsl-list/651070"
> EasyUnsubscribe</a>
(<a style="color: blue;"
href="mailto:xsl-list-unsub@lists.mulberrytech.com?subject=remove"
> by email</a>)
</div>
</div>
<!-- end bl.html.trailer --></div>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic