On Fri, Nov 19, 2010 at 06:37:19PM +0100, Michael Ludwig wrote: > money_seshu Dronamraju schrieb am 19.11.2010 um 10:20 (+0530): > > > > Problem description: EXSLT date:add() adds days to xs:gYearMonth/xs:gYear > > incorrectly when month is January > > > > The following 2 expressions returns incorrect date: > > <xsl:value-of select="date:add( "2001-01", "P3D" )" /> -> returns > > 2001-01 > > <xsl:value-of select="date:add( "2001", "P12D" )')" /> -> returns > > 2001 > > Ideally it should return "2001-01-04" and "2001-01-13" respectively. > > > > Root cause: > > > > In _exsltDateAdd(..,..) function ( libxslt/trunk/libexslt/date.c) > > > > Because the month is January(1), "if" condition will never evaluate to true, > > even though the day was changed , so it never returns return type as XS_DATE > > > > Patch: attached. > > > > Please provide your comments. > > I haven't tried your patch, but here's a standalone copy/paste testcase to > confirm the issue: > > <xsl:stylesheet version="1.0" > xmlns:date="http://exslt.org/dates-and-times" > exclude-result-prefixes="date" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output indent="yes"/> > <xsl:template match="/"> > <dates-and-times> > <d><xsl:value-of select="date:add( '2001-01', 'P3D' )" /></d> > <d><xsl:value-of select="date:add( '2001-02', 'P3D' )" /></d> > <d><xsl:value-of select="date:add( '2001-12', 'P3D' )" /></d> > <d><xsl:value-of select="date:add( '2001-12', 'P30D' )" /></d> > <d><xsl:value-of select="date:add( '2001-12', 'P31D' )" /></d> > <d><xsl:value-of select="date:add( '2001-12', 'P32D' )" /></d> > </dates-and-times> > </xsl:template> > </xsl:stylesheet> > > $ xsltproc exslt-date.xsl exslt-date.xsl > > <?xml version="1.0"?> > <dates-and-times> > <d>2001-01</d> > <d>2001-02-04</d> > <d>2001-12-04</d> > <d>2001-12-31</d> > <d>2002-01</d> > <d>2002-01</d> > </dates-and-times> > > January seems problematic indeed.
Okay, by applying the patch this looks indeed better: paphio:~/XSLT/tests/general -> cat date_add.out <?xml version="1.0"?> <dates-and-times> <d>2001-01-04</d> <d>2001-02-04</d> <d>2001-12-04</d> <d>2001-12-31</d> <d>2002-01</d> <d>2002-01-02</d> </dates-and-times> </dates-and-times> But should '2001-12' plus 31 days areally generate "2002-01" and not "2002-01-01", I'm wondering ? Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ [email protected] | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ _______________________________________________ xslt mailing list, project page http://xmlsoft.org/XSLT/ [email protected] http://mail.gnome.org/mailman/listinfo/xslt
