xsl-list
[Top] [All Lists]

RE: Problem with date:add

2006-02-15 06:58:06
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
From: "Andrew Smith" <andrew(_dot_)smith(_at_)itility(_dot_)co(_dot_)uk>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: [xsl] Problem with date:add
Date: Wed, 15 Feb 2006 10:18:24 -0000

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="date:difference">
        <xsl:with-param
name="start">2006-02-10T15:38:00</xsl:with-param>
        <xsl:with-param name="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="date:difference">
        <xsl:with-param
name="start">2006-02-10T15:38:00</xsl:with-param>
        <xsl:with-param name="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="date:difference">
        <xsl:with-param
name="start">2006-02-10T15:38:00</xsl:with-param>
        <xsl:with-param name="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="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>

causes the crash and

<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>

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

--~------------------------------------------------------------------
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>
--~--


_________________________________________________________________
Are you using the latest version of MSN Messenger? Download MSN Messenger 7.5 today! http://messenger.msn.co.uk


--~------------------------------------------------------------------
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>