Newsgroups: comp.lang.apl
Path: watmath!watserv1!utgpu!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!think.com!mips!darwin.sura.net!haven.umd.edu!socrates!socrates!rockwell
From: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Subject: Re: julian day number in J
In-Reply-To: jph@astro.umd.edu's message of 8 May 92 14:00:12 GMT
Message-ID: <ROCKWELL.92May13211648@socrates.umd.edu>
Sender: rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell)
Organization: Traveller
References: <13158@umd5.umd.edu>
Date: Thu, 14 May 1992 02:16:48 GMT
Lines: 38

J. Patrick Harrington:
   A classic exercise is finding elapsed days between two calendar
   dates. Astronomers use a running count called the Julian day number
   for this purpose. Here is my obfuscated translation of
   Duffett-Smith's BASIC subroutine for this. Anyone have a better
   one?

I've always considered date munging a rather obfuscated exercise [lots
of 'arbitrary' considerations].  However, the following definition of
julian gives the same result as your version.  You'll have to decide
for yourself whether my comments are appropriate:

......................................................................

l    =. '0# body=:body,y.':''     NB. body builder
body =. 0 0 $ ''

l '''dmy''=. y.                     NB. unpack day, month, and year'
l ' mon  =. m + 12    * m < 3     NB. put Februrary at end of the year'
l ' yr   =. y + (y<0) - m < 3     NB. correct for Feb fix, and no year 0'
l ' skip =. 0 <: 3 #. |. * y. - 15 10 1582 NB. skip oct 5-14, 1582'
l ' cen =. <. yr % 100                     NB. century number'
l ' x =. skip * 2 + (<. cen % 4) - cen     NB. pre-1583 corrections'
l ' ydays =. <. 365.25  * yr     '
l ' mdays =. <. 30.6001 * mon + 1'
l '1720994.5+x+ydays+mdays+d               NB. 1 Jan 1 AD <--> 1721423.5'

julian =. body : '' "1

......................................................................

It may be possible to simplify this further, but I'd have to sit down
and chart out all the possibilities...  [I don't have any other
references handy on the formulation of Julian dates.]

Hope this helps,

Raul
