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: fdd80,47b877165af3dad0 X-Google-Attributes: gidfdd80,public X-Google-Thread: 1164f8,47b877165af3dad0 X-Google-Attributes: gid1164f8,public X-Google-Thread: ffc31,47b877165af3dad0 X-Google-Attributes: gidffc31,public From: Kevin Handy Subject: Re: Y2K Conversion of Date to Internal Format Date: 1998/08/17 Message-ID: <35D84FE1.2B2ACA19@srv.net>#1/1 X-Deja-AN: 381988269 Content-Transfer-Encoding: 7bit References: <35D63BEB.2A9533BB@idirect.com> To: Jerome Fine Content-Type: text/plain; charset=us-ascii X-Complaints-To: newsabuse@supernews.com X-Trace: 903368411 HLLAGTWDS7F81CDB4C usenet53.supernews.com Organization: Software Solutions, Inc Mime-Version: 1.0 Newsgroups: vmsnet.pdp-11,alt.sys.pdp11,comp.os.vms,comp.sys.dec Jerome Fine wrote: > 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 ) I am assuming this is the call to the following code. > 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 > where all variables are 16 bit integers. Obviously the value overflows and > becomes negative on 13-Sep-1999 which is exactly what is wanted. I don't see it overflowing, unless I am missing something obvious.As long as you pass in the full year, it looks like it should work to me. It appears to be trying to calculate the julian date for the first day of the month, or something approximately like it. > I have taken a few liberties with the FORTRAN code since I wanted > to make the algorithm clear. > > The problem is that the algorithm BREAKS on 01-Mar-2000 at which > point the DATE value reverts to the same value as for 06-Feb-2000 > and 24 duplicates are created. There is also a routine which works in > the opposite direction which just ignores the first set of duplicate days > from 06-Feb-2000 to 29-Feb-2000. I'd suspect you are overflowing an integer. (2000 - 1910) * 365 = 32850 Where a 16 bit signede integer is limited to -32768 to 3767 Probibly overflowed in the year (32767 / 365) + 1910 = 1999.77 ie. Somewhere in the 3rd quarter of 1999. My only suggestion is to change the base year from 1910 to something later, but it will break any existing data is is stored in a file. If you are not storing it in a file, than I'd look at the dates it needs to process and set it to the earliest that you need to handle. It depends on what you are doing with the number returned. > (A) Is anyone familiar with an algorithm which works to convert > to the internal format and in the reverse direction? > (B) The size is important since I MUST patch the application > programs, NOT compile and link. > > I suspect that someone thought we should revert to the old > calendar when those 11? days were lost and give everyone a > change to live 24 days a second time. Anyone remember > the names of the old and the present calendar which was > modified to take into account those extra leap years? I > though a bit of humour might make the question a bit > more interesting? > > Sincerely yours, > > Jerome Fine > RT-11/TSX-PLUS User/Addict > Year 2000 Solutions for Legacy RT-11 Applications > (Sources not always required)