SRFI-19: Fix TAI->UTC conversions, leap second handling, etc.

Fixes <https://bugs.gnu.org/21911>.
Fixes <https://bugs.gnu.org/22034>.
Fixes <https://bugs.gnu.org/21902>.
Partially fixes <https://bugs.gnu.org/21904>.
Reported by Zefram <zefram@fysh.org>.

* doc/ref/srfi-modules.texi (SRFI-19 Introduction): Fix the definitions
of Julian Day and Modified Julian Day.  Give the correct full names of
UTC and TAI.
* module/srfi/srfi-19.scm: Import (srfi srfi-1).  Use modern Guile
keyword syntax in the 'define-module' form.
(leap-second-neg-delta): New procedure, derived from a similar procedure
in the latest upstream SRFI-19 reference implementation.
(priv:time-tai->time-utc!, time-tai->julian-day)
(time-monotonic->julian-day): Use 'leap-second-neg-delta'.
(local-tz-offset): Fix comment.
(leap-second?): Remove.
(tai-before-leap-second?): New procedure, derived from upstream SRFI-19.
(time-utc->date): Use 'define*' to handle the optional argument.  Remove
the leap second handling, following upstream SRFI-19.
(time-tai->date): Rewrite in terms of 'time-utc->date'.  Add special
leap second handling, following upstream SRFI-19.
(time-monotonic->date): Rewrite in terms of 'time-tai->date'.
(date->time-tai, date->time-monotonic): Add special leap second
handling, following upstream SRFI-19.
(directives): In the entry for the "~Y" escape in 'date->string', pad
the year field to 4 characters, following upstream SRFI-19.
* test-suite/tests/srfi-19.test: Add tests.
This commit is contained in:
Mark H Weaver 2018-10-20 03:34:56 -04:00 committed by Andy Wingo
commit e00563492a
3 changed files with 182 additions and 102 deletions

View file

@ -2402,8 +2402,8 @@ functions and variables described here are provided by
@cindex UTC
@cindex TAI
This module implements time and date representations and calculations,
in various time systems, including universal time (UTC) and atomic
time (TAI).
in various time systems, including Coordinated Universal Time (UTC)
and International Atomic Time (TAI).
For those not familiar with these time systems, TAI is based on a
fixed length second derived from oscillations of certain atoms. UTC
@ -2435,18 +2435,14 @@ in @file{srfi-19.scm} for how to update this table.
@cindex julian day
@cindex modified julian day
Also, for those not familiar with the terminology, a @dfn{Julian Day}
is a real number which is a count of days and fraction of a day, in
UTC, starting from -4713-01-01T12:00:00Z, ie.@: midday Monday 1 Jan
4713 B.C. A @dfn{Modified Julian Day} is the same, but starting from
1858-11-17T00:00:00Z, ie.@: midnight 17 November 1858 UTC. That time
is julian day 2400000.5.
represents a point in time as a real number of days since
-4713-11-24T12:00:00Z, i.e.@: midday UT on 24 November 4714 BC in the
proleptic Gregorian calendar (1 January 4713 BC in the proleptic Julian
calendar).
@c The SRFI-1 spec says -4714-11-24T12:00:00Z (November 24, -4714 at
@c noon, UTC), but this is incorrect. It looks like it might have
@c arisen from the code incorrectly treating years a multiple of 100
@c but not 400 prior to 1582 as non-leap years, where instead the Julian
@c calendar should be used so all multiples of 4 before 1582 are leap
@c years.
A @dfn{Modified Julian Day} represents a point in time as a real number
of days since 1858-11-17T00:00:00Z, i.e.@: midnight UT on Wednesday 17
November AD 1858. That time is julian day 2400000.5.
@node SRFI-19 Time