Re: [HACKERS] Pre-1970 dates under Win32

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Kurt Roeckx <Q(at)ping(dot)be>
Cc: Claudio Natoli <claudio(dot)natoli(at)memetrics(dot)com>, "'pgsql-hackers-win32(at)postgresql(dot)org'" <pgsql-hackers-win32(at)postgresql(dot)org>, "'pgsql-hackers(at)postgresql(dot)org'" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] Pre-1970 dates under Win32
Date: 2004-02-02 08:08:05
Message-ID: 447.1075709285@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-hackers-win32

Kurt Roeckx <Q(at)ping(dot)be> writes:
> I had a discussion about time_t some weeks ago. There is nothing
> in the standard that says time_t must be a signed, all it says is
> that (time_t)(-1) represents an invalid value.

Don't get me started :-(

No sane person (certainly no one born before 1970) would think that
there is no need to represent pre-1970 dates. Also, anyone who harbors
ambitions of still being around 40 years from now will realize that the
current 32-bit range of time_t is inadequate. Fortunately, Moore's law
will save us. We can simply move to a 64-bit, signed representation of
time_t, maintaining the 1970 origin for compatibility's sake. That will
hold us till, if not the heat death of the universe, at least an epoch
where no one will blink an eye at 128-bit time_t. It will also provide
a standardized representation for pre-1901 times, something we lack now.

Given that that's surely where we'll be in a few years, I can see no
reason to abandon the past and pretend that time_t should be unsigned.

The special case for -1 is certainly a wart, but it's not a flaw in the
datatype definition, just a bug in the APIs of a few libc routines that
couldn't be bothered with providing a separate error return value.
These routines could be deprecated, the same way the ones with
non-reentrant APIs have been deprecated.

AFAIK all the old-line Unix implementations consider time_t signed.
I quote for example the HPUX man page for mktime():

If the calendar time cannot be represented, the
function returns the value (time_t)-1 and sets errno
to ERANGE. Note the value (time_t)-1 also
corresponds to the time 23:59:59 on Dec 31, 1969
(plus or minus time zone and Daylight Saving Time
adjustments). Thus it is necessary to check both
the return value and errno to reliably detect an
error condition.

In any case, making the type unsigned hardly makes the -1 special case
go away, it simply moves it out to 2100-something.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2004-02-02 08:28:00 Re: Idea about better configuration options for sort memory
Previous Message Karel Zak 2004-02-02 07:57:49 Re: msg translation into sk_SK, Docs: SGML -> XML

Browse pgsql-hackers-win32 by date

  From Date Subject
Next Message Jan Wieck 2004-02-02 15:33:42 Re: [HACKERS] What's left?
Previous Message Kurt Roeckx 2004-02-02 07:37:37 Re: [HACKERS] Pre-1970 dates under Win32