From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f7344,47b877165af3dad0 X-Google-Attributes: gidf7344,public X-Google-Thread: 1164f8,47b877165af3dad0 X-Google-Attributes: gid1164f8,public X-Google-Thread: ffc31,47b877165af3dad0 X-Google-Attributes: gidffc31,public X-Google-Thread: fdd80,47b877165af3dad0 X-Google-Attributes: gidfdd80,public From: Jerome Fine Subject: Re: Y2K Conversion of Date to Internal Format Date: 1998/08/21 Message-ID: <35DD8F5C.ED2765B7@idirect.com>#1/1 X-Deja-AN: 383366179 Content-Transfer-Encoding: 7bit References: <35D8AD45.458E8C95@idirect.com> <01bdcac2$35061860$7df84018@fsys.wave.shaw.ca> <01bdcb38$5fecbf40$2e0f4018@fsys.wave.shaw.ca> <35DB845F.918A044@idirect.com> <199808201251.HAA30561@x8.dejanews.com> To: Pierre.Bru@spotimage.fr Content-Type: text/plain; charset=us-ascii X-Trace: 21 Aug 1998 15:17:38 GMT, ts6-34t-9.idirect.com Organization: "Usenet User" MIME-Version: 1.0 Newsgroups: vmsnet.pdp-11,alt.sys.pdp11,comp.os.vms,comp.sys.dec >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)