[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">&lt;<a href="mailto:xsl-list-service@lists.mulberrytech.com" \
target="_blank">xsl-list-service@lists.mulberrytech.com</a>&gt;</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 &quot;malformed \
forms&quot; are due to omitted seconds and if it is only the date you are interested \
in, truncate values at the separator &#39;T&#39; 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&#39;t \
need to worry about the time values, so this is the approach I&#39;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">&lt;<a \
href="mailto:xsl-list-service@lists.mulberrytech.com" \
target="_blank">xsl-list-service@lists.<wbr>mulberrytech.com</a>&gt;</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&#39;m \
wondering about best practices when dealing with potentially malformed dates. I \
confess that I haven&#39;t worked with dates (xs:date, xs:time, xs:dateTime) very \
much and so I&#39;m not sure if I&#39;m thinking about things correctly. \
<br><br></div>I have the following input:<br>       &lt;test&gt;<br>              \
&lt;field name=&quot;publication_date&quot; type=&quot;date&quot;&gt;<br>             \
&lt;value&gt;2011-12-01T00:00-08:00&lt;<wbr>/value&gt;<br>              \
&lt;/field&gt;<br>              &lt;field name=&quot;embargo_date&quot; \
type=&quot;date&quot;&gt;<br>                     \
&lt;value&gt;2011-12-01T00:00-08:00&lt;<wbr>/value&gt;<br>              \
&lt;/field&gt;<br>              \
&lt;submission-date&gt;2011-11-17T08<wbr>:11:17-08:00&lt;/submission-date&gt;<br>     \
&lt;publication-date&gt;2011-12-01T0<wbr>0:00-08:00&lt;/publication-date&gt;<br>      \
&lt;/test&gt;<br><br></div>And I&#39;d like to do a comparison check on the \
field[@name=&#39;embargo_date&#39;] vs the output of current-dateTime(). I have the \
following stylesheet:<br><br>&lt;?xml version=&quot;1.0&quot; \
encoding=&quot;UTF-8&quot;?&gt;<br>&lt;xsl:stylesheet xmlns:xsl=&quot;<a \
href="http://www.w3.org/1999/XSL/Transform" \
target="_blank">http://www.w3.org/1<wbr>999/XSL/Transform</a>&quot;<br>       \
xmlns:xs=&quot;<a href="http://www.w3.org/2001/XMLSchema" \
target="_blank">http://www.w3.org/20<wbr>01/XMLSchema</a>&quot;<br>       \
exclude-result-prefixes=&quot;xs&quot;<br>       version=&quot;2.0&quot;&gt;<br>      \
<br>       &lt;xsl:output encoding=&quot;UTF-8&quot; indent=&quot;yes&quot; \
method=&quot;xml&quot;/&gt;<br>       <br>       <br>       &lt;xsl:variable \
name=&quot;c-dateTime&quot;<br>                                  \
select=&quot;dateTime(xs:date(forma<wbr>t-date(current-date(), \
&#39;[Y]-[M,2]-[D,2]&#39;)),<br>                                                      \
xs:time(format-time(current-ti<wbr>me(), &#39;[H]:[m]:[s][Z]&#39;)))&quot;/&gt;<br>   \
<br>   &lt;xsl:template match=&quot;/&quot;&gt;<br>           &lt;xsl:variable \
name=&quot;test-dateTime&quot; as=&quot;xs:dateTime&quot; \
select=&quot;test/field[@name=&#39;emba<wbr>rgo_date&#39;]/value&quot;/&gt;<br>       \
<br>           &lt;result&gt;&lt;xsl:value-of select=&quot;if ($test-dateTime ge \
$c-dateTime ) then &#39;embargo me!&#39; else &#39;all \
clear!&#39;&quot;/&gt;&lt;/result&gt;<br>       \
&lt;/xsl:template&gt;<br>&lt;/xsl:stylesheet&gt;<br><br></div>I&#39;m using Saxon \
HE-9.6.0.7 in oXygen 18.1, which gives me a compile time error of &quot;FORG0001: \
Invalid dateTime value &quot;2018-12-01T00:00-08:00&quot; (Wrong delimiter after \
minute)&quot;. <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=&#39;embargo_date&#39;] 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