GNU bug report logs - #26151
date-year-day screws up leap days prior to AD 1

Previous Next

Package: guile;

Reported by: Zefram <zefram <at> fysh.org>

Date: Sat, 18 Mar 2017 01:12:02 UTC

Severity: normal

Done: Mark H Weaver <mhw <at> netris.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 26151 in the body.
You can then email your comments to 26151 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#26151; Package guile. (Sat, 18 Mar 2017 01:12:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Zefram <zefram <at> fysh.org>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sat, 18 Mar 2017 01:12:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Zefram <zefram <at> fysh.org>
To: bug-guile <at> gnu.org
Subject: date-year-day screws up leap days prior to AD 1
Date: Sat, 18 Mar 2017 01:10:58 +0000
In SRFI-19, the date-year-day function is meant to return the ordinal
day of the year for a date structure.  This value is properly 1 for the
first day of each calendar year, and on all other days 1 greater than
the value for the preceding day.  But the implementation occasionally
has it repeat a value:

scheme@(guile-user)> (use-modules (srfi srfi-19))
scheme@(guile-user)> (date-year-day (julian-day->date 1719657 0))
$1 = 59
scheme@(guile-user)> (date-year-day (julian-day->date 1719658 0))
$2 = 60
scheme@(guile-user)> (date-year-day (julian-day->date 1719659 0))
$3 = 60

and occasionally has it skip a value:

scheme@(guile-user)> (date-year-day (julian-day->date 1720023 0))
$4 = 59
scheme@(guile-user)> (date-year-day (julian-day->date 1720024 0))
$5 = 61

These errors happen around the end of February in years preceding AD 1.
In each leap year a value is repeated (ordinal values 1 too low from
March to December), and in each year immediately following a leap year
a value is skipped (ordinal values 1 too high from March to December).
Looking at the code, the bug arises from confusion between astronomical
year numbering (which leap-year? expects to receive) and the bizarre
zero-skipping year numbering that the library uses in the date structure
(which date-year-day passes, via year-day, to leap-year?).

Since the subject's come up: that year numbering used in the date
structures is surprising, and I'm not sure quite what to make of it.
It matches AD year numbering for years AD 1 onwards, but then numbers AD
0 (1 BC) as -1, and numbers all earlier years in accordance with that.
It's almost a straight linear numbering of years, except that it skips
the number 0.  (At least you've documented it.)  This is not a convention
that I've seen in real use anywhere else, and that weird exception to
the linearity makes it a pain to use.  It's likely to cause bugs in
user code, along the lines of the library bug that I've reported above
and the previously-reported bug#21903.  However, I haven't reported the
year numbering per se as a bug, because SRFI-19 doesn't actually say
what numbering is to be used for the date-year slot.

If I had implemented SRFI-19 myself, without reference to existing
implementations, I would have implemented astronomical year numbering
(consistent AD year numbering, extending linearly in both directions),
as used in ISO 8601.  This is the most conventional year numbering,
and at a stretch one could read SRFI-19 as implying it, by using some AD
year numbering and not saying to deviate from that scheme.  But really the
standard is silent on the issue.  Since the signification of date-year is
an interoperability issue, this silence is a problem, and it is troubling
that you and I have reached different interpretations of the standard
on this point.

Where did you get the idea to use a non-linear year numbering?  What's
your opinion of SRFI-19's (lack of) text on this matter?  You should
consider the possibility of changing your implementation to use the
conventional astronomical year numbering in this slot.

-zefram




Information forwarded to bug-guile <at> gnu.org:
bug#26151; Package guile. (Sat, 18 Mar 2017 09:41:01 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: <tomas <at> tuxteam.de>
To: bug-guile <at> gnu.org
Subject: Re: bug#26151: date-year-day screws up leap days prior to AD 1
Date: Sat, 18 Mar 2017 10:40:22 +0100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, Mar 18, 2017 at 01:10:58AM +0000, Zefram wrote:

[...]

> Where did you get the idea to use a non-linear year numbering?  What's
> your opinion of SRFI-19's (lack of) text on this matter?  You should
> consider the possibility of changing your implementation to use the
> conventional astronomical year numbering in this slot.

It seems that there are both conventions, "with year zero" (astronomical)
and "without year zero" (the more "conventional" historical usage (aka
"Common Era"), see [1].

That said, these days (and ISO 8601) go by "with year zero". Therefore
I'd sympathize with your tendency. Perhaps an option or a different set
of functions might satisfy both camps?

Definitely it needs to be documented.

Regards
[1] https://en.wikipedia.org/wiki/Year_zero

- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAljNAIUACgkQBcgs9XrR2kZwUgCfen5ea8HCGVZzXCZd3ErwGi2V
MwoAnA+0Au3tNQNiFKJ1mcsMDHl6iCeT
=w9Dn
-----END PGP SIGNATURE-----




Information forwarded to bug-guile <at> gnu.org:
bug#26151; Package guile. (Tue, 25 Apr 2017 07:58:01 GMT) Full text and rfc822 format available.

Message #11 received at 26151 <at> debbugs.gnu.org (full text, mbox):

From: Andy Wingo <wingo <at> pobox.com>
To: Zefram <zefram <at> fysh.org>
Cc: 26151 <at> debbugs.gnu.org
Subject: Re: bug#26151: date-year-day screws up leap days prior to AD 1
Date: Tue, 25 Apr 2017 09:57:41 +0200
On Sat 18 Mar 2017 02:10, Zefram <zefram <at> fysh.org> writes:

> If I had implemented SRFI-19 myself, without reference to existing
> implementations, I would have implemented astronomical year numbering
> (consistent AD year numbering, extending linearly in both directions),
> as used in ISO 8601.  This is the most conventional year numbering,
> and at a stretch one could read SRFI-19 as implying it, by using some AD
> year numbering and not saying to deviate from that scheme.  But really the
> standard is silent on the issue.  Since the signification of date-year is
> an interoperability issue, this silence is a problem, and it is troubling
> that you and I have reached different interpretations of the standard
> on this point.
>
> Where did you get the idea to use a non-linear year numbering?  What's
> your opinion of SRFI-19's (lack of) text on this matter?  You should
> consider the possibility of changing your implementation to use the
> conventional astronomical year numbering in this slot.

For what it's worth the "you" in your message refers to "hackers of
yore" ;-) I mean, this code's core was last changed in 2001 by a Guile
maintainer a few generations back.  The fact that it's lasted this long
does indicates that it's generally acceptable, but the fact that you
have found so many bugs indicates that there are parts of it that aren't
so good.  And it's old old code that needs modernizing (proper data
structures, pattern matching, and so on).

What I mean to say is that if there's a more sensible thing to do, we
can do it.

To answer your specific question: would this be an ABI change in some
way, or can we make this change in 2.2?

Andy




Reply sent to Mark H Weaver <mhw <at> netris.org>:
You have taken responsibility. (Sun, 21 Oct 2018 20:40:01 GMT) Full text and rfc822 format available.

Notification sent to Zefram <zefram <at> fysh.org>:
bug acknowledged by developer. (Sun, 21 Oct 2018 20:40:02 GMT) Full text and rfc822 format available.

Message #16 received at 26151-done <at> debbugs.gnu.org (full text, mbox):

From: Mark H Weaver <mhw <at> netris.org>
To: Zefram <zefram <at> fysh.org>
Cc: 26151-done <at> debbugs.gnu.org
Subject: Re: bug#26151: date-year-day screws up leap days prior to AD 1
Date: Sun, 21 Oct 2018 16:38:50 -0400
This is fixed by commit a58c7abd72648f77e4ede5f62a2c4e7969bb7f95 on the
stable-2.2 branch.  I'm closing this bug now, but please reopen if
appropriate.

     Thanks!
       Mark




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 19 Nov 2018 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 158 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.