Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
In this case, true. HoursBetween returns 0. However, Delphi 7 does have issues with it's asserts but on to the reason why HoursBetween is failing.
Keep in mind, TDateTime is a double--and floating point numbers are by definition inprecise. You are trying to increment this number by 1/24th of a day--or 0.041666666667. If you immediately look at the difference between the times after doing so, you will note that it is 0.041666666664. This effect is caused by the implict round off error that happens whenever you try to represent an inprecise number precisely.
If you want precise date and time calculations you must use an integral date and time format (such as SYSTEMTIME or FILETIME).
To illustrate this, if you create a new project, drop a memo field (with the font set to Courier New) and a button on it and insert the following code associating the OnClick event in the button with the code Button1Click below,
function Pad (S : string; L : Integer) : string;
begin Result := S; while Length(Result) < L do begin Result := Result+' '; end; end;
procedure TForm1.Button1Click(Sender: TObject);
var dt1 : TDateTime; dt2 : TDateTime; I : Integer;
begin Memo1.Clear; Memo1.Lines.Add('Hours MillisecondsBewteen Result Expected Result'); Memo1.Lines.Add('----- -------------------------- ---------------'); for I := 1 to 60 do begin dt1 := Now; dt2 := IncHour(dt1,I); Memo1.Lines.Add(Pad(IntToStr(I),5)+' '+Pad(IntToStr(MillisecondsBetween(dt1,dt2)),26) +' '+IntToStr(I*3600000)); end; end;
It has nothing to do with the Assert. I just use this Assert to show what's wrong. What this post is about is that if i do a IncHour on a date, then i expect that the HoursBetween this new and old date would be 1. But it isn't. However, if i do a IncHour by 2, then the HoursBetween function results 2. So then it does work good. I think it's a bug. But maybe somebody has an explanation for it.
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
Thanks for your answer. I already thought that it would be caused by rounding errors, but still i find the way these specific routines work not satisfactory. These methods should take the roundoff errors into account. I program to the interface, not the implementation. If the interface says "this method increments a date/time with one hour", and another method says "i tell you the difference between two date/times in hours", i expect them to behave according to this interface. So when i call the second method after using the first, it should tell me that 1 hour has passed. But this is ofcourse my point of view, and who am i? ;]
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html,
social networking links, message board signature, company profile, etc.