[fpc-pascal] FileAge() issue?

silvioprog silvioprog at gmail.com
Sat Jan 16 01:42:53 CET 2016


On Fri, Jan 15, 2016 at 4:15 AM, Michael Van Canneyt <michael at freepascal.org
> wrote:

> On Thu, 14 Jan 2016, silvioprog wrote:
>
>> Hello,
>>
>> I'm trying to get the datetime from a file, but it seems that the
>> FileAge()
>> function doesn't work properly. See only the second from the results
>> below:
>>
>> FPC: 20/05/2014 10:33:*50*
>>
>
> It seems like a rounding difference.
>
> home: >ls -l --time-style=+'%Y-%m-%d %H:%M:%S' COPYING.txt -rw-r--r-- 1
> michael michael 1579 2014-05-20 10:33:50 COPYING.txt
>

Hm... now I did another test avoiding the formater function:

begin
  WriteLn(FileAge('COPYING.txt'));
  WriteLn('Press [ENTER] to exit ...');
  ReadLn;
end

I got the same integer result on FPC and Delphi, so the FileAge() function
works fine.


> home: >./testfpc
> 20-5-14 09:33:50
> Press [ENTER] to exit ...
>
> So the actual timestamp is probably a border case value.


You are right, and it seems more related to the datetime formater function,
so I did this change:

FPC/Delphi:

var
  VDt: TDateTime;
begin
  FileAge('COPYING.txt', VDt);
  WriteLn(FormatDateTime('mm/dd/yyyy hh:nn:ss.zzz', VDt));
  WriteLn('Press [ENTER] to exit ...');
  ReadLn;
end

FPC (3.1.1 - trunk): 05/20/2014 10:33:*50.000*

Comparing it with Delphi (using same FPC code) and Node
(console.log(stat.mtime.*toISOString*()):

Delphi (Seattle): 05/20/2014 10:33:*49.646*

Node: 2014-05-20T13:33:*49.646*Z

--
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160115/5c0ade56/attachment.html>


More information about the fpc-pascal mailing list