[fpc-devel] Definition of the time-fration in a TDateTime before 30/12/1899

Michael Van Canneyt michael at freepascal.org
Sun May 21 16:40:44 CEST 2006



On Sun, 21 May 2006, Joost van der Sluis wrote:

> Hi all,
>
> I have some questions about the TDateTime format.
>
> I always thought that you could do this:
>   TD : TDateTime
>
> TD := EncodeDate()+encodeTime();
>
> This would mean that you have the following: (24-hours notation)
>
>  0     = 12/30/1899 00:00    (as defined)
>  1     = 12/31/1899 00:00
>  1.25  = 12/31/1899 06:00
> -1     = 12/29/1899 00:00
> -2     = 12/28/1899 00:00
> -1.25  = 12/28/1899 18:00    (-2+0.75)
>
> But now the Delphi help says:
>
> -1.25  = 12/29/1899 06:00

It's also what Delphi does.

>
> And this is how it's also implemented in FPC. But for instance
> PostgreSQL which also uses a format like TDateTime does it the other
> way. Which looks more logical to me, since if you want to know if
> DateTimeA is after DateTimeB you can do: DateTimeA>DateTimeB
>
> With the Delphi-help variant this won't work. Since -1>-1.25 but
> 12/29/1899 00:00 > 12/29/1899 06:00 doesn't make sence to me.
>
> This implementation will mean that if you compare TDateTime's you first
> have to check whether the date is before or after 12/30/1899 ?
>
> There are some bugs in DecodeDate, DecodeTime and friends for dates
> before 12/30/1899 but to fix those, I need to know what to do with this
> problem.

Keep delphi compatibility.

Also windows compatibility. TDateTime is a windows construct.
(see variants)

They obviously judged that the idea of
 TD := EncodeDate()+encodeTime();
was more important than strict ordering.

The following remark in the Delphi help sheds more light on the issue:

"When working with negative TDateTime values, computations must handle
time portion separately. The fractional part reflects the fraction of
a 24-hour day without regard to the sign of the TDateTime value.
For example,
  6:00 am on 12/29/1899 is -1.25,
Not
  -1 + 0.25,
which would be -0.75. There are no TDateTime values between -1 and 0."

So they are aware of the issue.

Michael.



More information about the fpc-devel mailing list