Re: DAY Number in an Year



Rich Townsend wrote:
> ttw@xxxxxxxxxxxxxxx wrote:
>> In 2003, I suggested:
>> FUNCTION juldate (year,month,day)
>> c
>> c Converts DAY/MONTH/YEAR to a Julian date transformed to 2000
>> c
>> IMPLICIT NONE
>> c
>> INTEGER juldate, day, month, year
>> c
>>
>> juldate=367*year-7*(year+(month+9)/12)/4-3*((year+(month-9)/7)/100
>>
>>
>> 1 +1)/4+275*month/9+day-730516
>> END
>>
>>
>> The constant 730516 can be adjusted to match any date desired as
>> the starting point or to change Gregorian dates to Julian.
>>
>
> Note, however, that Julian days formally begin at 12 noon. So your
> algorithm has an off-by-one error for AM vs PM.

For a one-to-one correspondence with calendar dates,
using round to nearest of the Julian day number is a good
choice. That's what the above produces. (Note that
astronomical day numbers are not integers, the fraction
of the day is part of the value.)

My complaint about the above is that it's difficult to
verify correctness. In the old days of programmable
pocket calculators and the like, saving space using
obscure formulae that didn't require any auxilliary
tables and such might have been appropriate. Today,
it's more important to be legible and verifiably correct.

In the same thread Dr. Warnock mentioned the above,
I recommended:

integer function dateval(m, d, y)
integer, intent(in):: m, d, y
integer, parameter:: ar(12) = (/365, 396, 59, 90, 120, 151, 181, &
212, 243, 273, 304, 334/)
integer :: yr
yr = y
if (m < 3) yr = y-1
dateval = yr*365 + yr/4 - yr/100 + yr/400 +ar(m) + d + 1721060
return
end

Originally, the leap day at the end of Feb. was at the end
of the year (March was the first month). With the change
to January as the first month, leap day was left as the
last of February. It's still easiest to calculate if leap
day is the last of the year however. So that's why the
first two months are adjusted as above. That's the
only confusing part of the algorithm. The rest is
clearly a direct application of the normal rules of
the Gregorian calendar. The 1721060 is the necessary
value for the Julian day number sequence (the first day
of which was chosen to be Jan 1, 4713 BC). Any number
can be chosen if you want a different initial date.

The above obviously doesn't check for valid dates. If the
day of the month or the year are impossible or way out of
range, the returned value is meaningless. The month
is not checked either unless array bounds checking is turned
on. On the other hand, for valid Gregorian dates (more
recent then Oct 15, 1582 and for as far in the future as
I expect to survive - at least assuming default INTEGERs
are at least 23 bits) the returned result should be correct.
To get the fractional Julian day number, take the time of
day (in hours), subtract 12, divide by 24.0 and add to the
above calculated integer.

> PS I'm talking about the astronomical Julian calendar, as created by Julius
> Scalinger. For some reason, many programmers refer to the days-since-arbitrary
> epoch (say, 1900 or 1970) as the Julian date, but that's just wrong.

Actually it was invented by Jacob Scalinger and named for his
father, whose name was Julius.

--
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare


.



Relevant Pages

  • Re: It it now a leap year?
    ... even showing that the rules defined for leap ... Julian or Gregorian? ... Didn't Pope Gregory fixed the calendar, ...
    (Fedora)
  • Re: dates of Chaldea and new Chaldea
    ... The Gregorian calendar has existed only since 1582 AD ... the Julian constant leap year of 180 days every 720 years ... has been the Julian calendar from 45 BC to 1582 AD ...
    (talk.origins)
  • Re: January 1st 1 AD ?
    ... (There were no leap years in the old style calendar. ... The Julian calendar *did* have leap years, giving an average year of 365.25 days. ...
    (comp.lang.java.programmer)
  • convert julian date to calendar date in excel
    ... If you have your Julian date on A1 then on B1: ... should be the same exept for leap ... >Does anyone know how to convert julian date to calendar ... date in excel? ...
    (microsoft.public.excel.misc)
  • Re: Happy Birthday Julius Caesar!
    ... Clearly the disorders of the Roman calendar before the Julian reform, ... Romans from thinking of July 13 as Caesar's birthday long after his death (proof ... year in the Julian system but not the Gregorian, ...
    (alt.talk.royalty)