xsl-list
[Top] [All Lists]

RE: Problem with date:add

2006-02-16 02:51:49
Thanks for the replies, I've changed the XSLT so that the duration is
inside single quotes, so the new code now looks like this
(/root/@CurrentDateTime contains the current date and time in the valid
format, 2006-02-16T09:42:00 at the moment)

<xsl:variable name="thirtyDaysAgo">
   <xsl:call-template name="date:add">
      <xsl:with-param name="date-time" select="/root/@CurrentDateTime"/>
      <xsl:with-param name="duration" select="'-P30D'" />
   </xsl:call-template>
</xsl:variable>

However, this still causes a timeout on the page (I'm guessing because
of an infinite loop or trying to get a negative date?) and

<xsl:variable name="thirtyDaysAgo">
   <xsl:call-template name="date:add">
      <xsl:with-param name="date-time" select="/root/@CurrentDateTime"/>
      <xsl:with-param name="duration" select="'P30D'" />
   </xsl:call-template>
</xsl:variable>

Returns 2006-02-46T09:45:00

Thanks for any more help that you can give
Andy
-----Original Message-----
From: xsl-list-digest-help(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:xsl-list-digest-help(_at_)lists(_dot_)mulberrytech(_dot_)com] 
Sent: 16 February 2006 06:10
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: xsl-list Digest 16 Feb 2006 06:10:00 -0000 Issue 692

Date: Wed, 15 Feb 2006 10:18:24 -0000
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
From: "Andrew Smith" <andrew(_dot_)smith(_at_)itility(_dot_)co(_dot_)uk>
Subject: Problem with date:add
Message-ID:
<76965BD96EE0A94C96C835E37C2F526015E570(_at_)sgserver01(_dot_)StottGroup(_dot_)local>

Hi,

I was looking for a way to easily check if a date was less than 30 days
old using XSLT and came across http://www.exslt.org which had several
useful date templates, however, none of them seem to do what I'd like.
My initial thought would be to use date:difference, if the difference
was more than 30 then I'd know it was an 'old' date, otherwise it'd be a
'new' date. However, it doesn't work quite like I'd expect since (as
shown below) it doesn't return the 'correct' values (I know this is by
design from reading the page).

<xsl:call-template name=3D"date:difference">
        <xsl:with-param
name=3D"start">2006-02-10T15:38:00</xsl:with-param>
        <xsl:with-param
name=3D"end">2006-02-08T15:38:00</xsl:with-param>
</xsl:call-template>

would return '-P2D' and (notice the end date is now in January not
February)

<xsl:call-template name=3D"date:difference">
        <xsl:with-param
name=3D"start">2006-02-10T15:38:00</xsl:with-param>
        <xsl:with-param
name=3D"end">2006-01-08T15:38:00</xsl:with-param>
</xsl:call-template>

would also return '-P2D' where what I'd expect is '-P33D' or '-P1M2D'

<xsl:call-template name=3D"date:difference">
        <xsl:with-param
name=3D"start">2006-02-10T15:38:00</xsl:with-param>
        <xsl:with-param
name=3D"end">2006-01-31T15:38:00</xsl:with-param>
</xsl:call-template>

then returns 'P21D' and not '-P11D'. So my next attempt was to use
date:add and 'add' -30 days, however, this also doesn't work, resulting
in a time out. This is because it doesn't support date roll overs (i.e.
reaching the start/end of one month doesn't move on to the end/start of
the next month) and so

<xsl:variable name=3D"thirtyDaysAgo">
        <xsl:call-template name=3D"date:add">
                <xsl:with-param name=3D"date-time"
select=3D"2006-02-10T15:38:00" />
                <xsl:with-param name=3D"duration">-P30D</xsl:with-param>
        </xsl:call-template>
</xsl:variable>

causes the crash and

<xsl:variable name=3D"thirtyDaysAgo">
        <xsl:call-template name=3D"date:add">
                <xsl:with-param name=3D"date-time"
select=3D"2006-02-10T15:38:00" />
                <xsl:with-param name=3D"duration">P30D</xsl:with-param>
        </xsl:call-template>
</xsl:variable>

returns '2006-32-10T15:38:00'

So, after all of this, my question to the list is, is there an easy way
to see if a stored date is less than 30 days old, either using these
templates or any other templates.

Thanks for any help
Andy

------------------------------

Date: Wed, 15 Feb 2006 16:40:14 +0530
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
From: Mukul Gandhi <gandhi(_dot_)mukul(_at_)gmail(_dot_)com>
Subject: Re: [xsl] Problem with date:add
Message-ID:
<7870f82e0602150310m3614ae32hec8c038e2d4c5edb(_at_)mail(_dot_)gmail(_dot_)com>

On 2/15/06, Andrew Smith <andrew(_dot_)smith(_at_)itility(_dot_)co(_dot_)uk> 
wrote:

       <xsl:call-template name=3D"date:add">
               <xsl:with-param name=3D"date-time"
select=3D"2006-02-10T15:38:00" />
               <xsl:with-param
name=3D"duration">-P30D</xsl:with-param>
       </xsl:call-template>


You are making mistake with the syntax in select. The correct format
is (please note single quotes)

<xsl:call-template name=3D"date:add">
    <xsl:with-param name=3D"date-time" select=3D"'2006-02-10T15:38:00'"
/>
    <xsl:with-param name=3D"duration" select=3D"'-P30D'" />
</xsl:call-template>

Regards,
Mukul

------------------------------

Date: Wed, 15 Feb 2006 13:58:06 +0000
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
From: "Vasu Chakkera" <vasucv(_at_)hotmail(_dot_)com>
Subject: RE: [xsl] Problem with date:add
Message-ID: <BAY113-F3EB71C5D9E30869AAEBBBCBFA0(_at_)phx(_dot_)gbl>

havent gone through the problem completely, but noticed a possible cause
for 
your problem.
<xsl:variable name="thirtyDaysAgo">
        <xsl:call-template name="date:add">
                <xsl:with-param name="date-time"
select="2006-02-10T15:38:00" />
                <xsl:with-param name="duration">P30D</xsl:with-param>
        </xsl:call-template>
</xsl:variable>

your date time value is not in quotes. Note that any string literal
inside a 
select must be in quotes.Otherwise it is assumed to be selecting a node
with 
name given in the select .

If you find it difficult, put the value of the string literal inside the

body. like you did for the "duration"

HTH
Vasu

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>