Incorrect result of function FileAge, when date 12-30-1899 lazarus / 66-Unix ---------------------------------------------------------------------- 7bit · 2025-02-23 08:14 I found that if the file modification date in the system is 12/30/1899 (TDateTime value = 0), the FileAge returns an incorrect result. Here is the code that demonstrates the problem: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,  BaseUnix, DateUtils; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation { TForm1 } procedure TForm1.Button1Click(Sender: TObject);var  FlNm: String;  Utime: UtimBuf;  St: stat;begin  FlNm := GetTempDir + 'temp.tmp';  with TFileStream.Create(FlNm, fmCreate) do  begin    Free;  end;   //UTime.modtime := DateTimeToUnix(StrToDateTime('30-12-1901'));  UTime.modtime := DateTimeToUnix(0);  UTime.actime := UTime.modtime;  FpUtime(FlNm, @Utime);   // invalid time  ShowMessage(FormatDateTime('dd-mm-yyyy', UnixToDateTime(FileAge(FlNm))));   // valid time  FpStat(FlNm, St);  ShowMessage(FormatDateTime('dd-mm-yyyy', UnixToDateTime(St.st_mtime)));end; initialization  {$I unit1.lrs} end.                                              Lazarus/FPC version: Lazarus 4.0RC2 (rev lazarus_4_0RC2-104-gb0513d9031) FPC 3.2.2 x86_64-linux-gtk2 ---------------------------------------------------------------------- MarkMLl · 2025-02-23 09:01 What happens if that's a simple non-GUI program? What date does the OS show for the file? Is it different depending on what utility you use? What filesystem are you using? Does the date survive an fsck? I'm troubled by the fact that unix- in general- has no support for files older than its own epoch, so trying to force things might lead to inconsistent results. MarkMLl ---------------------------------------------------------------------- 7bit · 2025-02-23 11:13 Here is a simple program: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; uses  SysUtils, Classes, BaseUnix, DateUtils; var  FlNm: String;  Utime: UtimBuf;  St: stat;begin  FlNm := GetTempDir + 'temp.tmp';  with TFileStream.Create(FlNm, fmCreate) do  begin    Free;  end;   UTime.modtime := DateTimeToUnix(0);  UTime.actime := UTime.modtime;  FpUtime(FlNm, @Utime);   // invalid time  WriteLn(FormatDateTime('dd-mm-yyyy', UnixToDateTime(FileAge(FlNm))));   // valid time  FpStat(FlNm, St);  WriteLn(FormatDateTime('dd-mm-yyyy', UnixToDateTime(St.st_mtime)));end.    The result is the same. File system is Ext4. Ouput of command ls -l: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #ls -l-rw-r --r-- 1 user user  0 дек 30  1899 temp.tmp  Result fsck i not check. Incorrect result of function FileAge, because it does not fit into the LongInt type. The Int64 type is required for the result. ---------------------------------------------------------------------- MarkMLl · 2025-02-23 11:44 Quote from: 7bit on February 23, 2025, 12:13:38 pmIncorrect result of function FileAge, because it does not fit into the LongInt type. The Int64 type is required for the result. Well deduced, in that case raise a bug report. MarkMLl ---------------------------------------------------------------------- Remy Lebeau · 2025-02-23 19:10 What about using the FileAge() overload that outputs a TDateTime  instead of an integer?