Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-01

FileAge() issue?

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

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*

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

NodeJS: Tue May 20 2014 10:33:*49* GMT-0300 (E. South America Standard Time)

C: Tue May 20 10:33:*49* 2014

Java: 05/20/2014 10:33:*49*

=== begin BAT code ===

C:\>for /f "delims=" %i in ('"forfiles /m COPYING.txt /c "cmd /c echo @fdate @ftime" "') do @echo %i

20/05/2014 10:33:*49*

=== end BAT code ===

My environment:

Lazarus 1.7 rUnknown FPC 3.1.1 i386-win32-win32/win64 on Windows 7

Download all sources used in the test here [1].

Thank you!

[1] - https://www.dropbox.com/s/lm40ge0jxccq38w/fileage.zip?dl=1

Silvio Clécio

Reply by email

Michael Van Canneyt
to silvioprog
silvioprog wrote 6 lines
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

home: >./testfpc
20-5-14 09:33:50
Press [ENTER] to exit ...

So the actual timestamp is probably a border case value.

Michael.

Reply by email

silvioprog
to Michael Van Canneyt

On Fri, Jan 15, 2016 at 4:15 AM, Michael Van Canneyt <

Show quoted text 19 lines
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.

Show quoted text 5 lines
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

Reply by email

silvioprog
to silvioprog

On Fri, Jan 15, 2016 at 9:42 PM, silvioprog wrote: [...]

Show quoted text 9 lines
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

It seems a bug in the fpc datetime formater func:

:~$ ls -l --time-style=+'%Y-%m-%d %H:%M:%S.%3N' COPYING.txt -rwxrwx--- 1 silvioprog silvioprog 1579 2014-05-20 10:33:*49.646* COPYING.txt

Env:

:~$ fpc
Free Pascal Compiler version 3.1.1 [2015/10/20] for x86_64 Copyright (c) 1993-2015 by Florian Klaempfl and others

:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.3 LTS
Release: 14.04
Codename: trusty

Silvio Clécio

Reply by email

Sven Barth
to silvioprog: On Fri, Jan 15, 2016 at 4:15 AM, Michael Van Canneyt < Hm... now I did another test…
"silvioprog" wrote 9 lines
On Fri, Jan 15, 2016 at 4:15 AM, Michael Van Canneyt < 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:

Show quoted text 7 lines
>> >> 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

Show quoted text 11 lines
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.

Show quoted text 10 lines
> > 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:

Show quoted text 15 lines
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

Reply by email

silvioprog
to Sven Barth

On Sat, Jan 16, 2016 at 5:29 AM, Sven Barth
wrote:
[...]

Show quoted text 5 lines
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)

The truncation should be disabled by default, but allowing to disable it via some flag. It would make the FPC date format function compatible with Delphi and many other compilers and languages.

Silvio Clécio

Reply by email