[fpc-devel] Magic numbers used in TryEncodeDate
Graeme Geldenhuys
graemeg.lists at gmail.com
Thu Apr 20 16:47:26 CEST 2006
What is the meaning of these magic numbers used in the TryEncodeDate method?
I would like to document them for FPC once I know the answer.
146097
1461
153
693900
I saw the constant DateDelta, but that is never used in TryEncodeDate
(whereas in Delphi it is).
DateDelta = 693594; // Days between 1/1/0001 and 12/31/1899
All of this came about while trying to understand why I get a
different results when I do the following under Delphi and FPC:
dt := EncodeDate(1652, 6, 15) + EncodeTime(12, 34, 56, 12);
and then format dt to a string as "yyyy-mm-dd hh:mm:ss"
Result under Delphi 7:
expected: <1652-06-15 12:34:56> but was: <1652-06-16 11:25:03>
Result under FPC:
expected: <1652-06-15 12:34:56> and got it.
----------------------------------------------------------------
Function TryEncodeDate(Year,Month,Day : Word; Var Date : TDateTime) : Boolean;
var
c, ya: cardinal;
begin
Result:=(Year>0) and (Year<10000) and
(Month in [1..12]) and
(Day>0) and (Day<=MonthDays[IsleapYear(Year),Month]);
If Result then
begin
if month > 2 then
Dec(Month,3)
else
begin
Inc(Month,9);
Dec(Year);
end;
c:= Year DIV 100;
ya:= Year - 100*c;
Date := (146097*c) SHR 2 + (1461*ya) SHR 2 +
(153*cardinal(Month)+2) DIV 5 + cardinal(Day) - 693900;
end
end;
----------------------------------------------------------------
Regards,
- Graeme -
--
There's no place like 127.0.0.1
More information about the fpc-devel
mailing list