From c21fe206b08ec948a70edcd24ba5030d7634fab9 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Wed, 10 Oct 2007 14:34:38 +0000 Subject: applied patch from Maurice van der Pot to fix EXSLT week-in-year extenson * libexslt/date.c tests/exslt/date/datetime.1.out tests/exslt/date/date.1.out tests/exslt/date/date.1.xml: applied patch from Maurice van der Pot to fix EXSLT week-in-year extenson which was not conforming to the definition. This also changes the output of the tests a bit. Should fix #452876 Daniel svn path=/trunk/; revision=1446 --- libexslt/date.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'libexslt') diff --git a/libexslt/date.c b/libexslt/date.c index 2325de33..1127e18a 100644 --- a/libexslt/date.c +++ b/libexslt/date.c @@ -2129,7 +2129,7 @@ static double exsltDateWeekInYear (const xmlChar *dateTime) { exsltDateValPtr dt; - long fdiy, fdiw, ret; + long diy, diw, year, ret; if (dateTime == NULL) { #ifdef WITH_TIME @@ -2147,20 +2147,26 @@ exsltDateWeekInYear (const xmlChar *dateTime) } } - fdiy = DAY_IN_YEAR(1, 1, dt->value.date.year); - + diy = DAY_IN_YEAR(dt->value.date.day, dt->value.date.mon, + dt->value.date.year); + /* * Determine day-in-week (0=Sun, 1=Mon, etc.) then adjust so Monday * is the first day-in-week */ - fdiw = (_exsltDateDayInWeek(fdiy, dt->value.date.year) + 6) % 7; - - ret = (DAY_IN_YEAR(dt->value.date.day, dt->value.date.mon, - dt->value.date.year) + fdiw) / 7; + diw = (_exsltDateDayInWeek(diy, dt->value.date.year) + 6) % 7; /* ISO 8601 adjustment, 3 is Thu */ - if (fdiw <= 3) - ret += 1; + diy += (3 - diw); + if(diy < 1) { + year = dt->value.date.year - 1; + if(year == 0) year--; + diy = DAY_IN_YEAR(31, 12, year) + diy; + } else if (diy > DAY_IN_YEAR(31, 12, dt->value.date.year)) { + diy -= DAY_IN_YEAR(31, 12, dt->value.date.year); + } + + ret = ((diy - 1) / 7) + 1; exsltDateFreeDate(dt); -- cgit v1.2.3