From: Jerome Fine <jhfine@idirect.com>
To: Pierre.Bru@spotimage.fr
Subject: Re: Y2K Conversion of Date to Internal Format
Date: 1998/08/21 [thread overview]
Message-ID: <35DD8F5C.ED2765B7@idirect.com> (raw)
In-Reply-To: 199808201251.HAA30561@x8.dejanews.com
>Pierre.Bru@spotimage.fr wrote:
> here is a DCL version of the R.G. Tantzen algorithm that convert gregorian
> date to julian day number and back. all is integer arithmetic and 32-bit
> integers.
Jerome Fine replies:
Thank you very much. Do you have a reference for this algorithm?
Very often, the source of some information leads to some more that
is also useful.
> this algorithm is year-2000-proof, leap-year-proof, century-leap-year-proof
> and you can compute julain day with this algorithm back to the begining of
> the gregorian calendar, october 15, 1582.
The best information I have here is the start date of the Gregorian Calendar!!!
I presume that 1600, 1700, 1800 and 1900 were all non-leap years.
And from the algorithm, it would seem that every future century is also a
non-leap year except when it is a millennium. Just how far does that rule
hold in the future and might the earth's rotation be slowing enough such
that in the future, some millennium will also no longer be a leap year?
> I can give you explanations for all these 'magic' numbers if you want.
Thank you. Rob Brown was able to do so already. If you have a different
interpretation, please add to the explanation.
> Pierre.
>
> $!------------------------------------------------------------------------------
> $!
> $! d/m/y -> julian
> $
> $ if m.gt.2
> $ then
> $ m = m - 3
> $ else
> $ m = m + 9
> $ y = y - 1
> $ endif
> $
> $ c = y / 100
> $ y = y - 100*c
> $
> $ j = c*146097/4 + y*1461/4 + (m*153 + 2)/5 + d + 1721119
> $
> $!------------------------------------------------------------------------------
> $ write sys$output "julian day: ''j'"
> $!------------------------------------------------------------------------------
> $!
> $! julian -> d/m/y
> $
> $ j = j - 1721119
> $
> $ y = (4*j - 1)/146097
> $ j = (4*j - 1)-146097*y
> $ d = j/4
> $
> $ j = (4*d + 3)/1461
> $ d = (4*d + 3)-1461*j
> $ d = (d+4)/4
> $
> $ m = (5*d - 3)/153
> $ d = (5*d - 3)-153*m
> $ d = (d+5)/5
> $
> $ y = y*100 + j
> $
> $ if m.lt.10
> $ then
> $ m = m + 3
> $ else
> $ m = m - 9
> $ y = y + 1
> $ endif
> $
> $!------------------------------------------------------------------------------
> $ write sys$output "''d' ''m' ''y'"
> $!------------------------------------------------------------------------------
The above algorithms seem just fine. But, unfortunately, although they
are obviously great for the problem they solve, I cannot use either for
the following 2 reasons:
(a) The base year is not 26-Dec-1909 and the application programs
must keep compatible with the existing data base, and
(b) They have too much code to fit in the same space as the original
algorithm which broke on 05-Feb-2000.
In addition, as a minor aspect, the algorithm which I suggested in my post
is likely to be a fair bit faster and use less memory. While it would need
a bit of tweaking to successfully cross 2000 from 1582, as well as not
having leap years for the centuries (I think I just repeated myself), the
use of a table driven method seems to be able to yield a faster answer.
If anyone would like a solution starting with 15-Oct-1582 to the
post I gave on 19-Aug-1998 22:05:19-04:00, I will try and re-work
my calculation. The key point is that in my calculation, there are many
fewer divisions and multiplication. Also, all the arithmetic can be
carried out in 16 bits except for the last step; thus only 2 more
instructions would be required to have a 32 bit result starting on
15-Oct-1582, plus the fudge factor because the centuries are
not leap years (complicated because 2000 is a leap year)
something like: ( 15 - Y / 100 ) + ( Y / 1000 - 1 ) which
becomes: Y / 1000 - Y / 100 + 14
Obviously, the table of days, DT, would change as well.
Just thinking on paper how my algorithm would change.
I also have an algorithm for the conversion of the julian date
to the M/D/Y. This algorithm is table driven and requires a
loop to determine the month via repeated comparisons.
It was just finished this morning and I haven't yet converted
it to assembler, but only 1 divide is required and one
multiply (and a shift for a divide by 4 for leap days). The
final loop to determine the month should require only 3
instructions a maximum of 12 tries. Since the only
arithmetic operation in the loop is a compare, the loop
should operate more quickly than a divide instruction,
at least on a PDP-11 since the average number of instructions
that will be executed in the loop is only 18. Note that I
expect that PIC can be used for both replacement subroutines
are that it will all fit into the same space as before.
Sincerely yours,
Jerome Fine
RT-11/TSX-PLUS User/Addict
Year 2000 Solutions for All RT-11/TSX-PLUS Applications
(Sources not always required)
next prev parent reply other threads:[~1998-08-21 4:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-08-17 4:00 Y2K Conversion of Date to Internal Format 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 [this message]
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 ` Pierre.Bru
1998-08-24 4:00 ` Martin Vorlaender
-- strict thread matches above, loose matches on Subject: below --
1998-08-15 4:00 Jerome Fine
1998-08-17 4:00 ` Kevin Handy
1998-08-17 4:00 ` Jim Becker
1998-08-20 4:00 ` George Cornelius
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