[xslt] exslt date bugs



Hello all;
   First off, I was entertained by Daniel apparently using xslt for the
first time, and finally discovering what cool tools he and
Thomas (& others ?) have been building!

   And secondly, I'm particularly enjoying the function & other
extensions that take a lot of the drudgey out of the `low-level'
part of xslt...

That said, the date spec is slightly screwy (why NaN for errors,
sometimes, and '' other times? (presumably double vs string return
types?;  and why is seconds required in times....)

But the main point is to provide some patches for some (mostly minor)
bugs in the date implementation.
   1) dDay format not recognized (trivial fix)
   2) Several functions are accepting dates in formats where they really
      haven't got sufficient information (trivial fix)
   3) week day & month names (abbreviated or not) when the date is not
      valid.  I'm actually surprised this doesn't segfault, as the
      current code casts a double to an int, and then references an
      array with the result, w/o any check.
      Is casting NaN to an int even defined?

Anyway, attached is
    diff date.c date.c.orig
and testdate.(dtd|xml|xsl)  to demonstrate

Thanks
700d699
< 	  ++cur;
1153,1154c1152
<     static const xmlChar monthNames[13][10] = {
<         { 0 },
---
>     static const xmlChar monthNames[12][10] = {
1170,1172c1168,1169
<     if (!VALID_MONTH(month))
<       month = 0;
<     return monthNames[month];
---
> 
>     return monthNames[month - 1];
1200,1201c1197
<     static const xmlChar monthAbbreviations[13][4] = {
<         { 0 },
---
>     static const xmlChar monthAbbreviations[12][4] = {
1217,1219c1213,1214
<     if(!VALID_MONTH(month))
<       month = 0;
<     return monthAbbreviations[month];
---
> 
>     return monthAbbreviations[month - 1];
1513c1508,1509
< 	if ((dt->type != XS_DATETIME) && (dt->type != XS_DATE)) {
---
> 	if ((dt->type != XS_DATETIME) && (dt->type != XS_DATE) &&
> 	    (dt->type != XS_GMONTHDAY) && (dt->type != XS_GDAY)) {
1549,1550c1545
<     static const xmlChar dayNames[8][10] = {
<         { 0 },
---
>     static const xmlChar dayNames[7][10] = {
1561,1563c1556,1557
<     if((day < 1) || (day > 7))
<       day = 0;
<     return dayNames[day];
---
> 
>     return dayNames[day - 1];
1588,1589c1582
<     static const xmlChar dayAbbreviations[8][4] = {
<         { 0 },
---
>     static const xmlChar dayAbbreviations[7][4] = {
1600,1602c1593,1594
<     if((day < 1) || (day > 7))
<       day = 0;
<     return dayAbbreviations[day];
---
> 
>     return dayAbbreviations[day - 1];
1638c1630,1631
< 	if ((dt->type != XS_DATETIME) && (dt->type != XS_TIME)) {
---
> 	if ((dt->type != XS_DATETIME) && (dt->type != XS_DATE) &&
> 	    (dt->type != XS_GMONTHDAY) && (dt->type != XS_GDAY)) {
1683c1676,1677
< 	if ((dt->type != XS_DATETIME) && (dt->type != XS_TIME)) {
---
> 	if ((dt->type != XS_DATETIME) && (dt->type != XS_DATE) &&
> 	    (dt->type != XS_GMONTHDAY) && (dt->type != XS_GDAY)) {
1728c1722,1723
< 	if ((dt->type != XS_DATETIME) && (dt->type != XS_TIME)) {
---
> 	if ((dt->type != XS_DATETIME) && (dt->type != XS_DATE) &&
> 	    (dt->type != XS_GMONTHDAY) && (dt->type != XS_GDAY)) {
<?xml version="1.0" encoding="ISO-8859-1"?>

<!ELEMENT page     (date*) >
<!ELEMENT date EMPTY>
<!ATTLIST date date CDATA #REQUIRED>
<?xml version="1.0"?>
<!DOCTYPE page PUBLIC "testdate" "testdate.dtd">
<page>
<date date="2001-10-29T10:31:07"/>
<date date="2001-10-29"/>
<date date="2001-10-fooT10:31:07"/>
<date date="foo"/>
<date date="---13"/>
</page>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
     xmlns:date="http://exslt.org/dates-and-times";
     extension-element-prefixes="date">

<xsl:template match="date">
Test Date : <xsl:value-of select="@date"/>
    <!-- dateTime, date, gYearMonth or gYear; else NaN -->
    year : <xsl:value-of select="date:year(@date)"/>
    <!-- dateTime, date, gYearMonth or gYear; else NaN -->
    leap-year    : <xsl:value-of select="date:leap-year(@date)"/>
    <!-- dateTime, date, gYearMonth, gMonth or gMonthDay; else NaN -->
    month-in-year: <xsl:value-of select="date:month-in-year(@date)"/>
    <!-- dateTime, date, gYearMonth or gMonth; else '' -->
    month-name   :  <xsl:value-of select="date:month-name(@date)"/>
    <!-- dateTime, date, gYearMonth or gMonth; else '' -->
    month-abbreviation   :  <xsl:value-of select="date:month-abbreviation(@date)"/>
    <!-- dateTime or date; else NaN -->
    week-in-year : <xsl:value-of select="date:week-in-year(@date)"/>
    <!-- dateTime, date; else NaN -->
    day-in-year  : <xsl:value-of select="date:day-in-year(@date)"/>
    <!-- dateTime, date, gMonthDay or gDay; else NaN -->
    day-in-month : <xsl:value-of select="date:day-in-month(@date)"/>
    <!-- dateTime, date; else NaN -->
    day-of-week-in-month : <xsl:value-of select="date:day-of-week-in-month(@date)"/>
    <!-- dateTime, date; else NaN -->
    day-in-week  : <xsl:value-of select="date:day-in-week(@date)"/>
    <!-- dateTime or time;  else '' -->
    time         : <xsl:value-of select="date:time(@date)"/>
    <!-- dateTime or time;  else NaN -->
    hour-in-day  : <xsl:value-of select="date:hour-in-day(@date)"/>
    <!-- dateTime or time;  else NaN -->
    minute-in-hour : <xsl:value-of select="date:minute-in-hour(@date)"/>
    <!-- dateTime or time;  else NaN -->
    second-in-minute : <xsl:value-of select="date:second-in-minute(@date)"/>
    <!-- dateTime or date; else NaN -->
    day-name     : <xsl:value-of select="date:day-name(@date)"/>
    <!-- dateTime or date; else NaN -->
    day-abbreviation : <xsl:value-of select="date:day-abbreviation(@date)"/>
</xsl:template>

</xsl:stylesheet>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]