diff --git a/src/main/pascal/PasBuild.Command.ProcessResources.pas b/src/main/pascal/PasBuild.Command.ProcessResources.pas index 90fdb06..793e31b 100644 --- a/src/main/pascal/PasBuild.Command.ProcessResources.pas +++ b/src/main/pascal/PasBuild.Command.ProcessResources.pas @@ -58,10 +58,10 @@ function TProcessResourcesCommand.GetName: string; function TProcessResourcesCommand.ApplyFiltering(const AContent: string): string; var - Now: TDateTime; + BuildDateTime: TDateTime; begin Result := AContent; - Now := SysUtils.Now; + BuildDateTime := TUtils.GetBuildDateTime(); // Replace project variables Result := StringReplace(Result, '${project.name}', Config.Name, [rfReplaceAll]); @@ -70,9 +70,9 @@ function TProcessResourcesCommand.ApplyFiltering(const AContent: string): string Result := StringReplace(Result, '${project.license}', Config.License, [rfReplaceAll]); // Replace build-time variables (ISO-8601 format) - Result := StringReplace(Result, '${build.date}', FormatDateTime('yyyy-mm-dd', Now), [rfReplaceAll]); - Result := StringReplace(Result, '${build.time}', FormatDateTime('hh:nn:ss', Now), [rfReplaceAll]); - Result := StringReplace(Result, '${build.timestamp}', FormatDateTime('yyyy-mm-dd''T''hh:nn:ss', Now), [rfReplaceAll]); + Result := StringReplace(Result, '${build.date}', FormatDateTime('yyyy-mm-dd', BuildDateTime), [rfReplaceAll]); + Result := StringReplace(Result, '${build.time}', FormatDateTime('hh:nn:ss', BuildDateTime), [rfReplaceAll]); + Result := StringReplace(Result, '${build.timestamp}', FormatDateTime('yyyy-mm-dd''T''hh:nn:ss', BuildDateTime), [rfReplaceAll]); end; function TProcessResourcesCommand.ProcessFile(const ASourceFile, ARelativePath: string): Boolean; diff --git a/src/main/pascal/PasBuild.Command.ProcessTestResources.pas b/src/main/pascal/PasBuild.Command.ProcessTestResources.pas index 03954ed..1a56bba 100644 --- a/src/main/pascal/PasBuild.Command.ProcessTestResources.pas +++ b/src/main/pascal/PasBuild.Command.ProcessTestResources.pas @@ -58,10 +58,10 @@ function TProcessTestResourcesCommand.GetName: string; function TProcessTestResourcesCommand.ApplyFiltering(const AContent: string): string; var - Now: TDateTime; + BuildDateTime: TDateTime; begin Result := AContent; - Now := SysUtils.Now; + BuildDateTime := TUtils.GetBuildDateTime(); // Replace project variables Result := StringReplace(Result, '${project.name}', Config.Name, [rfReplaceAll]); @@ -70,9 +70,9 @@ function TProcessTestResourcesCommand.ApplyFiltering(const AContent: string): st Result := StringReplace(Result, '${project.license}', Config.License, [rfReplaceAll]); // Replace build-time variables (ISO-8601 format) - Result := StringReplace(Result, '${build.date}', FormatDateTime('yyyy-mm-dd', Now), [rfReplaceAll]); - Result := StringReplace(Result, '${build.time}', FormatDateTime('hh:nn:ss', Now), [rfReplaceAll]); - Result := StringReplace(Result, '${build.timestamp}', FormatDateTime('yyyy-mm-dd''T''hh:nn:ss', Now), [rfReplaceAll]); + Result := StringReplace(Result, '${build.date}', FormatDateTime('yyyy-mm-dd', BuildDateTime), [rfReplaceAll]); + Result := StringReplace(Result, '${build.time}', FormatDateTime('hh:nn:ss', BuildDateTime), [rfReplaceAll]); + Result := StringReplace(Result, '${build.timestamp}', FormatDateTime('yyyy-mm-dd''T''hh:nn:ss', BuildDateTime), [rfReplaceAll]); end; function TProcessTestResourcesCommand.ProcessFile(const ASourceFile, ARelativePath: string): Boolean; diff --git a/src/main/pascal/PasBuild.Utils.pas b/src/main/pascal/PasBuild.Utils.pas index 43986db..bb30487 100644 --- a/src/main/pascal/PasBuild.Utils.pas +++ b/src/main/pascal/PasBuild.Utils.pas @@ -86,10 +86,16 @@ TUtils = class class function CollectSourceFiles(const ABaseDir: string): TStringList; class function CollectIncludeFiles(const ABaseDir: string): TStringList; class procedure WriteListFile(const AFilePath: string; AList: TStringList); + + { Build date utilities } + class function GetBuildDateTime(): TDateTime; end; implementation +uses + DateUtils; + { Forward declaration for recursive helper } procedure RecursiveScanDirs(const ADir: string; AList: TStringList); forward; @@ -889,4 +895,15 @@ class procedure TUtils.WriteListFile(const AFilePath: string; AList: TStringList end; end; +class function TUtils.GetBuildDateTime(): TDateTime; +var + SourceDateEpoch: string; +begin + SourceDateEpoch := GetEnvironmentVariable('SOURCE_DATE_EPOCH'); + if Length(SourceDateEpoch) > 0 then + Result := UnixToDateTime(StrToInt64(SourceDateEpoch)) + else + Result := SysUtils.Now() +end; + end.