[M3devel] leap-second issue with Date.i3

Mika Nystrom mika at async.caltech.edu
Sat Nov 10 12:33:03 CET 2007


Hello everyone,

I just ... added a workaround for a nasty bug I had in some code
of my own.  My code used Unix's localtime to convert a Time.T to a
Date.T using the zoneinfo files.  I'm not sure if there's a "normal"
way to do this in M3, so I have some messy stuff involving mutexes,
static storage, etc.  (Note one has to be careful when linking this
stuff into a program with the normal M3 conversion codes---Date.FromTime
and Date.ToTime---which also use (other) hidden mutexes to protect
some of the same data structures!)

The issue is this.  I just realized that localtime sometimes returns
"60" for the seconds---namely, during a leap second!  Just copying
this into a Date.T will lead to a range error and a program crash.
Do we really want Modula-3 users to have to restart their servers
the moment after popping the champagne corks?  (Ok, well during
New Year's Eve in my time zone, but still...)

Does anyone know how Date.T handles/should handle this?  As correct
as it is, I find it somewhat unsatisfying to change the seconds
field to [0..60], because off-by-one errors are so common in
programming... it's probably The Right Thing to do, though.

     Mika



More information about the M3devel mailing list