[xsl] RE: Problem with date:add

Subject: [xsl] RE: Problem with date:add
From: "Andrew Smith" <andrew.smith@xxxxxxxxxxxxx>
Date: Thu, 16 Feb 2006 09:51:49 -0000
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@xxxxxxxxxxxxxxxxxxxxxx
[mailto:xsl-list-digest-help@xxxxxxxxxxxxxxxxxxxxxx]
Sent: 16 February 2006 06:10
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
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@xxxxxxxxxxxxxxxxxxxxxx>
From: "Andrew Smith" <andrew.smith@xxxxxxxxxxxxx>
Subject: Problem with date:add
Message-ID:
<76965BD96EE0A94C96C835E37C2F526015E570@xxxxxxxxxxxxxxxxxxxxxxxxxxx>

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@xxxxxxxxxxxxxxxxxxxxxx
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Subject: Re: [xsl] Problem with date:add
Message-ID:
<7870f82e0602150310m3614ae32hec8c038e2d4c5edb@xxxxxxxxxxxxxx>

On 2/15/06, Andrew Smith <andrew.smith@xxxxxxxxxxxxx> 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@xxxxxxxxxxxxxxxxxxxxxx
From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
Subject: RE: [xsl] Problem with date:add
Message-ID: <BAY113-F3EB71C5D9E30869AAEBBBCBFA0@xxxxxxx>

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

Current Thread