[fpc-pascal] DateTimeToUnix bug?

Seth Grover sethdgrover at gmail.com
Tue Dec 30 17:25:29 CET 2008


I thought I'd get feedback here before I log this as a bug:

==================================================
program Project1;

uses
  Classes,
  SysUtils,
  DateUtils;

var
  utime  : longword;
  currentDt : TDateTime;
  convertedDt : TDateTime;
begin
  currentDt := EncodeDateTime(1989, 9, 16, 12, 0, 0, 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));

  currentDt := EncodeDateTime(1989, 9, 16, 12, 0, 1, 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));

  currentDt := EncodeDateTime(1989, 9, 16, 12, 0, 2, 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.
==================================================

The output I get (fpc 2.2.2 on linux) is:

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

It seems to me that 09-16-1989 12:00:01 should be 621950401, not 621950400.

Is this broken or am I missing something?

-sg

========================
Computer over. Virus = very yes.

Seth Grover
sethdgrover[at]gmail[dot]com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20081230/2921dcb1/attachment.html>


More information about the fpc-pascal mailing list