# Re: [xslt] Troubles with the EXSLT date extensions

• From: Igor Zlatkovic <igor stud fh-frankfurt de>
• To: <xslt gnome org>
• Subject: Re: [xslt] Troubles with the EXSLT date extensions
• Date: Tue, 17 Sep 2002 16:11:04 +0200

```Hi there,

> > I'll now check where the wrong numbers, that is those which differ from
the
> > correct result by more than d * -1, come from. I suspect the problem to
be
> > some odd double->long conversion, or similar.
>
>   Okay, you're in control, feel free to commit of course !

A second glance has revealed that not the datatype conversion plagues us,
but that the conversion of the duration to string is somewhat wrong, now
that we corrected the xy order :-) Look:

Given these arguments:
x = 2002-01-01T23:59:59
y = 2002-01-02T00:00:00
we can see that the difference is exactly one second. The relevant code in
libexslt computes the difference between the two dates and two times
separately, then it builds a sum of those differences. When it compares the
dates, it discovers that there is one day difference. When it compares the
times, it discovers the difference of -86339 sec. Adding these to each
other, 1 day + (-86339 sec) = 86340 sec + (-86339 sec), yields a duration of
one second. Still:
d = -P1DT23H59M59S
which is wrong. The formatting function, exsltDateFormatDuration, wrongly
assumes that the duration is negative if any one of the components (secs,
days, months, years) is negative, then it makes all negative components
positive and combines them. The truth is that these components must be
combined with regard to their sign, so that one year and negative twelve
months yield zero, for example. I'll fix that and hope all else will remain
unbroken.. Charlie? :-)

The old cal utility on any Unix tells another story:

[spell:~]\$ cal 9 1752
September 1752
Su Mo Tu We Th Fr Sa
1  2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

We can see that September 1752 in the gregorian calendar had few days less
than it normally does. If the x and y lay on different sides of that year,
our date:difference(x,y) will compute a wrong duration. Am I severly
misguided in my understanding of the gregorian calendar and if I am not,
shouldn't something be done here?

Ciao
Igor

```