DateTimeToFileDate

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

DateTimeToFileDate

Carsten Bager
When I do this

Free Pascal Compiler version 2.2.2 [2008/07/29] for i386
---------------------
Program tt;
uses dos,
     sysutils;

function strPackTime(t:longWord):shortstring;
var
  dt:Datetime;
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.
---------------------------------

I get this result

9/6-20160:28:22
11-9-08 13:39:55

What am I doing wrong.

Carsten
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: DateTimeToFileDate

Mattias Gaertner
Zitat von Carsten Bager <[hidden email]>:

> When I do this
>
> Free Pascal Compiler version 2.2.2 [2008/07/29] for i386

Which OS?

> ---------------------
> Program tt;
> uses dos,
>      sysutils;
>
> function strPackTime(t:longWord):shortstring;
> var
>   dt:Datetime;
> 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.
> ---------------------------------
>
> I get this result
>
> 9/6-20160:28:22
> 11-9-08 13:39:55
>
> What am I doing wrong.


Mattias

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: DateTimeToFileDate

Carsten Bager
> Zitat von Carsten Bager <[hidden email]>:
>
> > When I do this
> >
> > Free Pascal Compiler version 2.2.2 [2008/07/29] for i386
>
> Which OS?
Linux  

>
> > ---------------------
> > Program tt;
> > uses dos,
> >      sysutils;
> >
> > function strPackTime(t:longWord):shortstring;
> > var
> >   dt:Datetime;
> > 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.
> > ---------------------------------
> >
> > I get this result
> >
> > 9/6-20160:28:22
> > 11-9-08 13:39:55
> >
> > What am I doing wrong.
>
>
> Mattias
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: DateTimeToFileDate

Mattias Gaertner
On Sun, 14 Sep 2008 07:42:12 +0200
"Carsten Bager" <[hidden email]> wrote:

> > Zitat von Carsten Bager <[hidden email]>:
> >
> > > When I do this
> > >
> > > Free Pascal Compiler version 2.2.2 [2008/07/29] for i386
> >
> > Which OS?
> Linux  

AFAIK the unit Dos should not be used under Linux.


Mattias


> > > ---------------------
> > > Program tt;
> > > uses dos,
> > >      sysutils;
> > >
> > > function strPackTime(t:longWord):shortstring;
> > > var
> > >   dt:Datetime;
> > > 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.
> > > ---------------------------------
> > >
> > > I get this result
> > >
> > > 9/6-20160:28:22
> > > 11-9-08 13:39:55
> > >
> > > What am I doing wrong.
> >
> >
> > Mattias
> >
> > _______________________________________________
> > fpc-pascal maillist  -  [hidden email]
> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> >
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: DateTimeToFileDate

Carsten Bager
> 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


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: DateTimeToFileDate

Mattias Gaertner
On Sun, 14 Sep 2008 10:38:25 +0200
"Carsten Bager" <[hidden email]> wrote:

> > 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).

The FileDate format differ on unix and windows. UnpackTime uses the
windows format. You need another function for unix.


Mattias


>
> 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
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: DateTimeToFileDate

Carsten Bager
> The FileDate format differ on unix and windows. UnpackTime uses the
> windows format. You need another function for unix.

Is the file date on Unix the number of seconds since 00:00:00 January 1,
1970.

Carsten

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: DateTimeToFileDate

Jonas Maebe-2

On 14 Sep 2008, at 16:56, Carsten Bager wrote:

>> The FileDate format differ on unix and windows. UnpackTime uses the
>> windows format. You need another function for unix.
>
> Is the file date on Unix the number of seconds since 00:00:00  
> January 1,
> 1970.

Yes, and you also still have to adjust for the current time zone. It's  
probably easier to just use the regular rtl routines. If you want to  
program it yourself, search for datetime in rtl/unix/sysutils.pp


Jonas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal