Julian date routines needed

Jim Giles jlg at lanl.gov
Fri Feb 22 03:23:59 AEST 1991


>From article <408 at ceco.ceco.com>, by garry at ceco.ceco.com (Garry Garrett):
> [...]
> 	There is an easy way to do this.  Let UNIX do all the work FOR you.
> [...]
> Generally speaking, on a unix system, if you can convert the time that you
> are given, in whatever format you are given to either structure tm (defined
> in time.h) or into the number of seconds elapsed since jan 1, 1970 at 00:00:00,
> then you can do anything you want to with it.  [...]

You should be advised however that UNIX leaves dates before 1 Jan.
1970 completely undefined.  Further, on a 32 bit machine, the value
becomes undefined for dates after (about) 3 Jan. 2038 (the seconds
since epoch becomes negative then).  So, if your need for the Julian
Day Number is for something other than current events, the use of
built-in UNIX system features won't work.  The first chapter of the
'Numerical Recipes' book contains algorithms that work for all dates
since 4017 (I think) B.C..  It can easily be extended to be accurate
for all dates (I have a version which only overflows at year 40,000
(AD or BC)).

J. Giles



More information about the Comp.lang.c mailing list