[fpc-devel] Definition of the time-fration in a TDateTime before 30/12/1899
Joost van der Sluis
joost at cnoc.nl
Sun May 21 18:50:15 CEST 2006
On Sun, 2006-05-21 at 18:09 +0200, Michael Van Canneyt wrote:
>
> On Sun, 21 May 2006, Joost van der Sluis wrote:
>
> > On Sun, 2006-05-21 at 16:40 +0200, Michael Van Canneyt wrote:
> > > On Sun, 21 May 2006, Joost van der Sluis wrote:
> > > > 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.
> >
> > That also doesn't work. If td < 0 you must do:
> > TD := EncodeDate()+(1-EncodeTime());
>
> That is not correct, AFAIK ?
Right, I was wrong, but you still have to substract the time-part if the
date-part < 0.
Look at the example above:
TD := EncodeDate(1899,12,28)+EncodeTime(18,0,0,0); => -2 + 0.75 = -1.25
Volgens de Delphi help is -1.25 12/29/1899 06:00
But if you do this
EncodeDate(1899,12,28)-EncodeTime(18,0,0,0)); => -2 - 0.75 = -2.75
the result is correct.
So EncodeDate+EncodeTime won't work. But it will if you use mine
'logical' definition of TDateTime.
I really don't get the logics behind the Delphi-TDateTime format, maybe
only because Trunc(TDateTime) works so well to get the date-part. But
what about floor() ?
Joost.
More information about the fpc-devel
mailing list