From 1546ee8a14d186106b77277f4dd6c7b015acea3a Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 16 Oct 2025 01:40:13 +0200 Subject: [PATCH 1/2] Extend AUTODOC_FormatDate to deal with strings ... as used in the Date field of PackageInfo.g files. --- gap/ToolFunctions.gi | 20 ++++++++++++++++++++ tst/misc.tst | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/gap/ToolFunctions.gi b/gap/ToolFunctions.gi index 01fa6650..fa9fcb25 100644 --- a/gap/ToolFunctions.gi +++ b/gap/ToolFunctions.gi @@ -234,6 +234,7 @@ BindGlobal("AUTODOC_months", MakeImmutable([ # The input can be one of the following: # - AUTODOC_FormatDate(rec), where is a record with entries year, month, day; # - AUTODOC_FormatDate(year[, month[, day]]) +# - AUTODOC_FormatDate(date_str) where date_str is a string of the form "DD/MM/YYYY" or "YYYY-MM-DD" # In each case, the year, month or day may be given as either an # integer, or as a string representing an integer. InstallGlobalFunction( AUTODOC_FormatDate, @@ -241,6 +242,25 @@ function(arg) local date, key, val, result; if Length(arg) = 1 and IsRecord(arg[1]) then date := ShallowCopy(arg[1]); + elif Length(arg) = 1 and IsString(arg[1]) then + if Length(arg[1]) = 10 then + date := arg[1]; + if date{[3,6]} = "//" then + date := rec( + day := Int(date{[1,2]}), + month := Int(date{[4,5]}), + year := Int(date{[7..10]}), + ); + elif date{[5,8]} = "--" then + date := rec( + year := Int(date{[1..4]}), + month := Int(date{[6,7]}), + day := Int(date{[9,10]}), + ); + else + Unbind(date); + fi; + fi; elif Length(arg) in [1..3] then date := rec(); date.year := arg[1]; diff --git a/tst/misc.tst b/tst/misc.tst index 39549558..94c45c92 100644 --- a/tst/misc.tst +++ b/tst/misc.tst @@ -26,6 +26,10 @@ gap> AUTODOC_FormatDate(2019, 3, 1); "1 March 2019" gap> AUTODOC_FormatDate("2019", "3", "1"); "1 March 2019" +gap> AUTODOC_FormatDate("2019-03-01"); +"1 March 2019" +gap> AUTODOC_FormatDate("01/03/2019"); +"1 March 2019" gap> AUTODOC_FormatDate(rec(year:=2019)); "2019" gap> AUTODOC_FormatDate(rec(year:=2019, month:=3)); From 471aeb1ff356d6b10eca725a36e2662b3ab2e63c Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 16 Oct 2025 09:14:12 +0200 Subject: [PATCH 2/2] more --- CHANGES.md | 3 +++ gap/AutoDocMainFunction.gi | 16 +--------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3aed37cc..5ea3bfd2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,9 @@ This file describes changes in the AutoDoc package. 2025.MM.DD + - Make handling `Date` in `PackageInfo.g` more strict (previously some + malformed variants were accepted to deal with very old packages, but by + now all packages are compliant) - Remove a bunch of features that were deprecated since 2019: - `AutoDoc` option `scaffold.gapdoc_latex_options` has been replaced by `gapdoc.LaTeXOptions` diff --git a/gap/AutoDocMainFunction.gi b/gap/AutoDocMainFunction.gi index c2fa91bf..cdb17542 100644 --- a/gap/AutoDocMainFunction.gi +++ b/gap/AutoDocMainFunction.gi @@ -274,21 +274,7 @@ InstallGlobalFunction( CreateTitlePage, # digit day or month, which is formally not allowed in PackageInfo.g, # but happens in a few legacy packages) argument_rec.Date := Chomp( argument_rec.Date ); # remove trailing newlines, if present - i := SplitString( argument_rec.Date, "/" ); - if Length( argument_rec.Date ) in [8..10] and Length( i ) = 3 then - i := List(i, Int); - OutWithTag( "Date", AUTODOC_FormatDate(i[3], i[2], i[1]) ); - else - # try to parse the date in ISO8601 format YYYY-MM-DD (here we are strict) - i := SplitString( argument_rec.Date, "-" ); - if Length( argument_rec.Date ) = 10 and Length( i ) = 3 then - i := List(i, Int); - OutWithTag( "Date", AUTODOC_FormatDate(i[1], i[2], i[3]) ); - else - Info(InfoAutoDoc, 1, "Warning: could not parse package date '", argument_rec.Date, "'"); - OutWithTag( "Date", argument_rec.Date ); - fi; - fi; + OutWithTag( "Date", AUTODOC_FormatDate(argument_rec.Date) ); fi; for i in [ "Address", "Abstract", "Copyright", "Acknowledgements", "Colophon" ] do