[fpc-pascal] DateTimeToFileDate

Carsten Bager carsten at beas.dk
Sun Sep 14 10:38:25 CEST 2008


> AFAIK the unit Dos should not be used under Linux.
> 
> 
> Mattias

I rewrote the code omitting the dos unit, and got the fowing.
In my opinion the windows output and the Linux output should be (almost) 
the same, and then my conclusion is a compiler/rtl error.
Do you agree (I have also tested the 2.2.0 compiler and got the same 
result).

Carsten


Output from Linux compiler

Free Pascal Compiler version 2.2.0 [2007/08/31] for i386
Target OS: Linux for i386
12/6-2016 25:14:58
14-9-08 10:22:53

Output from Windows Compiler
Free Pascal Compiler version 2.2.2 [2008/08/03] for i386
Target OS: Win32 for i386

14/9-2008 10:21:42
14-09-2008 10:21:42


----------------------------------

Program tt;
uses sysutils;

Type
   Datetime_typ=Packed record
      year,month,day,hour,min,sec,sec100,dayOfWeek:word;
   end;

procedure UnpackTime(pdt:LongWord; var d:dateTime_typ);
begin
  d.sec:=(pdt and 31) *2;
  pdt:=pdt shr 5;
  d.min:=pdt and 63;
  pdt:=pdt shr 6;
  d.hour:=pdt and 31;
  pdt:=pdt shr 5;
  d.day:=pdt and 31;
  pdt:=pdt shr 5;
  d.month:=pdt and 15;
  pdt:=pdt shr 4;
  d.year:=pdt+1980;
end;

function strPackTime(t:longWord):shortstring;
var
  dt:Datetime_typ;
begin
  UnpackTime(t,dt);
  strPackTime:=intToStr(dt.day)+'/'+
         intToStr(dt.month)+'-'+
         intToStr(dt.year)+' '+
         intToStr(dt.hour)+':'+
         intToStr(dt.min)+':'+
         intToStr(dt.sec)+' ';
end;

Begin
  WriteLn(strPackTime(DateTimeToFileDate(now)));
  
WriteLn(DateTimeToStr(FileDateToDateTime(DateTimeToFileDate(now))))
;
End.
------------------------------------
Med venlig hilsen
Carsten Bager

BEAS A/S
Brørupvænget 10
DK-7650 Bøvlingbjerg
Tlf. : +45 9788 5222 Fax : +45 9788 5434
www.beas.dk





More information about the fpc-pascal mailing list