From: cornelius@eisner.decus.org (George Cornelius)
Subject: Re: Y2K Conversion of Date to Internal Format
Date: 1998/08/20 [thread overview]
Message-ID: <1998Aug20.015217.1@eisner> (raw)
In-Reply-To: 35D63BEB.2A9533BB@idirect.com
In article <35D63BEB.2A9533BB@idirect.com>, Jerome Fine <jhfine@idirect.com> writes:
> I am in the process of converting some application
> programs which have been written in FORTRAN.
> The complete package uses an internal DATE value
> which starts on 26-Dec-1909 as 0 and increases for
> each day. The algorithm which is broken is:
> DATE = CONVRT ( MONTH, DAY, YEAR )
> MONTH = MONTH - 2
> IF ( MONTH .LE. 0 ) MONTH = MONTH + 12; YEAR = YEAR - 1
> Q = YEAR / 100
> R = YEAR - Q * 100
> DATE = ( YEAR - 1910 ) * 365 + Q / 4 + R / 4 +
> ( MONTH + 1 ) * 28 + ( 26 * MONTH - 2 ) / 10
What's this, Zoeller's congruence with a year-2000 bug
thrown in for good measure?
The algorithm is dead wrong on century year calculations.
(It also is missing the +DAY term, but I'll assume that's
just a typo).
I'll rewrite your calculation as
(YEAR-1910)*365 + YEAR/400 + REM(YEAR,100)/4
+ 30*MONTH + (6*MONTH-2)/10
+ DAY + 28 ,
where REM is "remainder when divided by".
The first line tries, incorrectly, to compute an offset to
"first day" (March 1) of year, the second, offset from that
point to first day of month, the third to day of month.
REM(YEAR,100)/4 has a discontinuity (changes by -24) when
it hits any century year, and this is the source of the
problem.
For the first line try something like this instead:
(YEAR-1910)*365 + YEAR/4 - YEAR/100 + YEAR/400
(Every 4th year is a leap year, except every century year isn't,
except every multiple of 400 is). In fact, in your case (16 bit
unsigned result), the only century year you will encounter is
year 2000, so you can drop the last two terms of this line
entirely. Either way you will have to make an adjustment to
the constant term in order to have the desired base date.
--
George Cornelius cornelius@eisner.decus.org
cornelius@mayo.edu
next prev parent reply other threads:[~1998-08-20 4:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-08-15 4:00 Y2K Conversion of Date to Internal Format Jerome Fine
1998-08-17 4:00 ` Jim Becker
1998-08-17 4:00 ` Kevin Handy
1998-08-20 4:00 ` George Cornelius [this message]
-- strict thread matches above, loose matches on Subject: below --
1998-08-17 4:00 Jerome Fine
1998-08-19 4:00 ` Rob Brown
1998-08-19 4:00 ` Rob Brown
1998-08-19 4:00 ` Jerome Fine
1998-08-20 4:00 ` Pierre.Bru
[not found] ` <199808201251.HAA30561@x8.dejanews.com>
1998-08-21 4:00 ` Jerome Fine
1998-08-21 4:00 ` D.Webb
1998-08-22 4:00 ` Brian Inglis
1998-08-23 4:00 ` Charles Richmond
1998-08-24 4:00 ` Martin Vorlaender
1998-08-24 4:00 ` Pierre.Bru
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox