# Problems with JULDAY and CALDAT

• Subject: Problems with JULDAY and CALDAT
• From: "John J. Boia" <jboia(at)iasdev1.gsfc.nasa.gov>
• Date: Wed, 07 Apr 1999 12:28:11 -0400
• Newsgroups: comp.lang.idl-pvwave
• Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA
• Xref: news.doit.wisc.edu comp.lang.idl-pvwave:14256

```I've been developing a set of time conversion functions
(primarily using Modified Julian Date) and I have discovered
some problems with the IDL-provided routines CALDAT and JULDAY.

JULDAY seems to return Julian date values with an offset
of 0.5 from the accepted definition, when hours, minutes,
and seconds are passed in as arguments  Integer julian
day numbers correspond to 12:00 noon UT.

CALDAT does not correctly return the month/day/year
values for Julian day numbers that correspond to leap days
(Feb 29) in the leap years 1584 through 1604.  (It also
mishandles preceding leap years, but those are before the
the Gregorian calendar took effect in 1582 and it becomes
increasingly difficult to make sense of those dates anyway.)
Instead of Feb 29, (Year), it returns Feb 31, (Year+1).

The problems are easy enough to work around, if you know
what the problems are.  I have attached a small sample
procedure to demonstrate what I've found.  Does anyone
know of other problems, or a better pair of routines,
or a plan to update these two?

John Boia

PRO TIMETEST

FORWARD_FUNCTION JULDAY

B = julday( 1,1,1970,0,0,0 ) - 0.5D
PRINT, B, FORMAT="(' Jan 1 1970 0h UT --> JD ',F15.3//)"

FOR I = 2299160L, 2307639L DO BEGIN
CALDAT, I, MON, DAY, YR
JD = JULDAY( MON, DAY, YR )
IF I NE JD THEN BEGIN
FOR J = I-2, I+2 DO BEGIN
CALDAT, J, MON, DAY, YR
PRINT, J, MON, DAY, YR, FORMAT="(' JD =',I8,6x,'Cal:',3I5)"
ENDFOR
PRINT
ENDIF
ENDFOR

END

--
John J. Boia            | Email: jboia@iasdev1.gsfc.nasa.gov
Programmer/Analyst      | Web:   http://iasdev1.gsfc.nasa.gov/~jboia/
Computer Sciences Corp. | Phone: 301.794.2357

```