RESET #DATE-T(T) #DATE-DD(A2)
REDEFINE #DATE-T (#DD (P13))
MOVE EDITED #DATE-T(EM=DD) TO #DATE-DD
DISPLAY #DATE-DD#DD (EM=H(13))
END
Page 1 08-05-19 07:58:58
#DATE-DD#DD
02 0000000000000C
The RESET does indeed set #DATE-T to Binary zeroes (C of course is just the sign).
It is the “conversion” routine that converts a date/time variable to an alpha string for output (or a MOVE) that “creates” the strange date of January 2 0000
If we take the julian calendar (which was in use before 1582 A.D.) we got to more than 577813 days (1582 * 365 + 1580 / 4 = 577825). So it has to be the gregorian calendar with the special leap year rule. Let’s try to calculate back the internal date value of Natural to year 0:
define data local
1 #i4 (I4)
1 #year(I2)
1 #rem (N4)
1 #n4 (N4)
1 #leap (L)
end-define
*
#i4 := 577813 /* i.e. 1582-01-01
*
for #year = 1581 to 0 step -1
#i4 := #i4 - 365
*
* find out gregorian leap year
*
reset #leap
divide 400 into #year giving #n4 remainder #rem
if #rem = 0
#leap := true
else
divide 100 into #year giving #n4 remainder #rem
if #rem = 0
ignore
else
divide 4 into #year giving #n4 remainder #rem
if #rem = 0
#leap := true
end-if
end-if
end-if
if #leap
#i4 := #i4 - 1
end-if
write 'January 1' #year '-->' #i4 #leap
end-for
*
end
My output is:
January 1 1581 --> 577448
January 1 1580 --> 577082 X
January 1 1579 --> 576717
January 1 1578 --> 576352
January 1 1577 --> 575987
January 1 1576 --> 575621 X
[...]
January 1 5 --> 1826
January 1 4 --> 1460 X
January 1 3 --> 1095
January 1 2 --> 730
January 1 1 --> 365
January 1 0 --> -1 X
So: Zero point is January 2 0000
Questions:
Why is it the January 2 and not January 1?
Why is it year 0000? Year 0000 doesn’t exist in the julian and gregorian calendar.
Possible explanation: Year 0000 is 1 B.C. in reality which is not a leap year. Then the zero point would be January 1st 0001 B.C.
"It doesn’t prove that the conversion routine is wrong. "
I never said the conversion routine was wrong. I was merely pointing out that the conversion routine starts with a string of zeroes, which is what one would expect from a RESET, and produces something I find a bit strange, namely January 2, 0000.
Thanks Ralph for the tip on ZP; had never tried that. However, to my way of thinking, I should not have to turn ZP off to get rid of the “strange date”.
Of course, I cannot imagine someone trying to write out a RESET date variable in a production program. That leaves development. As a developer, I think I would probably want to see something like 00-00-0000 so I would know, if I were trying to follow some logic, that I had just RESET the variable, and had not modified it since then.