Date-oddity
"Tom Kise" <[email protected]>
| Newsgroups | gmane.text.xml.xslt.extensions |
|---|---|
| Organization | Privat |
| Message-ID | <000301c39fd6$44904870$0200000a@camel> |
Hi I have implemented a small web-solution, making use of the excellent exslt-date-module (Javascript/MSXSL-version). When using Date:Add I have experienced something odd, occuring only when the date is the last date in the month(!). My goal is to write a list of the month-names + year for 12 months, starting with the month of the current date. For the date 2003-10-31 the list should read october 2003, november 2003, december 2003, january 2004 an so forth until september 2004. The code is appended at the end of this mail. What I get (using the particular date 2003-10-31) is: October 2003, December 2003, December 2003, January 2004 March 2004 March 2004 May 2004 May 2004 July 2004 July 2004 August 2004 October 2004 Notice that several months is repeated and that some months is missing(!). Using any other date than the last day in each month, the functionality works fine. You can reproduce the oddity by setting the date on your computer to 2003-10-31 and run the following debug code in Javascript (using the Javascript/MSXSL-module): add(_formatDate(new Date(), "xs:date"), 'P1M'); This will return 2003-12-01, which obviously is not the intended date. What happens (in the EXSLT-module code), is that Javascript adds one day to the temporary (and illegal) date 2003-11-31 because there is no 31. nov, and thus ends up with 2003-12-01. What I should do is use the first day in each month, because in my case the day is not important, and this oddity will not occur. This mail is therefore sent for information or discussion only. Regards Mvh Tom Kise A: Julius Blomsgade 7, 3tv 2200 København Danmark M: [email protected] T: 35828111 <xsl:variable name="NoOfMonthInList" select="12"/> <xsl:variable name="Today" select="date:date()" /> <xsl:template match="/"> <xsl:call-template name="MonthLine"> <xsl:with-param name="No" select="0"/> </xsl:call-template> </xsl:template> <xsl:template name="MonthLine"> <xsl:param name="No"/> <xsl:if test="$NoOfMonthInList > $No"> <xsl:variable name="aMonthNo" select="date:monthInYear(date:parseDate(date:add($Today, concat(concat('P', $No), 'M')), 'xs:dateTime', 'xs:date'))" /> <xsl:variable name="aMonthName" select="date:monthName(date:parseDate(date:add($Today, concat(concat('P', $No), 'M')), 'xs:dateTime', 'xs:date'))" /> <xsl:variable name="aYear" select="date:year(date:parseDate(date:add($Today, concat(concat('P', $No), 'M')), 'xs:dateTime', 'xs:date'))" /> <b>·</b>  <a href="/show.asp?id=2210&MonthNo={$aMonthNo}&Year={$aYear}"> <xsl:value-of select="$aMonthName" />  <xsl:value-of select="$aYear" /> </a> <br/> <xsl:call-template name="MonthLine"> <xsl:with-param name="No" select="($No)+1"/> </xsl:call-template> </xsl:if> </xsl:template>