[fpc-pascal] FileAge() issue?

Sven Barth pascaldragon at googlemail.com
Sat Jan 16 09:29:29 CET 2016


Am 16.01.2016 01:43 schrieb "silvioprog" <silvioprog at gmail.com>:
>
> 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.646Z

I have not looked at the code, but from your results I'd say that we round
the value while others truncate them. At least in this context truncate
appears more correct though... (don't know if there is one where rounding
would be more correct)

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160116/86100998/attachment.html>


More information about the fpc-pascal mailing list