DateTimeToUnix rounding error
Original Reporter info from Mantis: sethdgrover@gmail.com
-
Reporter name: Seth Grover
Original Reporter info from Mantis: sethdgrover@gmail.com
- Reporter name: Seth Grover
Description:
I'm using FPC 2.2.2 on Linux (2.6.27-9-generic #1 SMP Thu Nov 20 21:57:00 UTC 2008 i686 GNU/Linux).
==================================================
program Project1;
uses
Classes, SysUtils, DateUtils;
var
utime : longword;
sec : word;
currentDt, convertedDt : TDateTime;
begin
for sec := 0 to 59 do begin
currentDt := EncodeDateTime(1989, 9, 16, 12, 0, sec, 0);
utime := DateTimeToUnix(currentDt);
convertedDt := UnixToDateTime(utime);
writeln(FormatDateTime('mm/dd/yyyy HH:nn:ss', currentDt) + ' = ' +
IntToStr(utime) + ' = ' +
FormatDateTime('mm/dd/yyyy HH:nn:ss',
convertedDt));
end;
end.
==================================================
This seems to be rounding error - if you put 1 ms (milisecond) in the
seconds test, the result comes out right.
For consecutive seconds, and ms = 0:
09-16-1989 12:00:00 = 621950400 = 09-16-1989 12:00:00
09-16-1989 12:00:01 = 621950400 = 09-16-1989 12:00:00
09-16-1989 12:00:02 = 621950402 = 09-16-1989 12:00:02
09-16-1989 12:00:03 = 621950403 = 09-16-1989 12:00:03
09-16-1989 12:00:04 = 621950403 = 09-16-1989 12:00:03
09-16-1989 12:00:05 = 621950404 = 09-16-1989 12:00:04
09-16-1989 12:00:06 = 621950406 = 09-16-1989 12:00:06
09-16-1989 12:00:07 = 621950407 = 09-16-1989 12:00:07
09-16-1989 12:00:08 = 621950407 = 09-16-1989 12:00:07
09-16-1989 12:00:09 = 621950408 = 09-16-1989 12:00:08
09-16-1989 12:00:10 = 621950410 = 09-16-1989 12:00:10
09-16-1989 12:00:11 = 621950411 = 09-16-1989 12:00:11
09-16-1989 12:00:12 = 621950411 = 09-16-1989 12:00:11
09-16-1989 12:00:13 = 621950412 = 09-16-1989 12:00:12
with ms = 1:
09-16-1989 12:00:00 = 621950400 = 09-16-1989 12:00:00
09-16-1989 12:00:01 = 621950401 = 09-16-1989 12:00:01
09-16-1989 12:00:02 = 621950402 = 09-16-1989 12:00:02
09-16-1989 12:00:03 = 621950403 = 09-16-1989 12:00:03
09-16-1989 12:00:04 = 621950404 = 09-16-1989 12:00:04
09-16-1989 12:00:05 = 621950405 = 09-16-1989 12:00:05
09-16-1989 12:00:06 = 621950406 = 09-16-1989 12:00:06
09-16-1989 12:00:07 = 621950407 = 09-16-1989 12:00:07
09-16-1989 12:00:08 = 621950408 = 09-16-1989 12:00:08
09-16-1989 12:00:09 = 621950409 = 09-16-1989 12:00:09
09-16-1989 12:00:10 = 621950410 = 09-16-1989 12:00:10
09-16-1989 12:00:11 = 621950411 = 09-16-1989 12:00:11
09-16-1989 12:00:12 = 621950412 = 09-16-1989 12:00:12
Mantis conversion info:
- Mantis ID: 12894
- Version: 2.2.2
- Fixed in version: 2.4.0
- Fixed in revision: 12958 (#6a813b8e)