Skip to content

Commit 85ec3f3

Browse files
authored
AUTODOC_FormatDate: directly parse Date in PackageInfo.g (#291)
1 parent 88e8e52 commit 85ec3f3

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
This file describes changes in the AutoDoc package.
22

33
2025.MM.DD
4+
- Make handling `Date` in `PackageInfo.g` more strict (previously some
5+
malformed variants were accepted to deal with very old packages, but by
6+
now all packages are compliant)
47
- Remove a bunch of features that were deprecated since 2019:
58
- `AutoDoc` option `scaffold.gapdoc_latex_options` has been
69
replaced by `gapdoc.LaTeXOptions`

gap/AutoDocMainFunction.gi

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -274,21 +274,7 @@ InstallGlobalFunction( CreateTitlePage,
274274
# digit day or month, which is formally not allowed in PackageInfo.g,
275275
# but happens in a few legacy packages)
276276
argument_rec.Date := Chomp( argument_rec.Date ); # remove trailing newlines, if present
277-
i := SplitString( argument_rec.Date, "/" );
278-
if Length( argument_rec.Date ) in [8..10] and Length( i ) = 3 then
279-
i := List(i, Int);
280-
OutWithTag( "Date", AUTODOC_FormatDate(i[3], i[2], i[1]) );
281-
else
282-
# try to parse the date in ISO8601 format YYYY-MM-DD (here we are strict)
283-
i := SplitString( argument_rec.Date, "-" );
284-
if Length( argument_rec.Date ) = 10 and Length( i ) = 3 then
285-
i := List(i, Int);
286-
OutWithTag( "Date", AUTODOC_FormatDate(i[1], i[2], i[3]) );
287-
else
288-
Info(InfoAutoDoc, 1, "Warning: could not parse package date '", argument_rec.Date, "'");
289-
OutWithTag( "Date", argument_rec.Date );
290-
fi;
291-
fi;
277+
OutWithTag( "Date", AUTODOC_FormatDate(argument_rec.Date) );
292278
fi;
293279

294280
for i in [ "Address", "Abstract", "Copyright", "Acknowledgements", "Colophon" ] do

gap/ToolFunctions.gi

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,33 @@ BindGlobal("AUTODOC_months", MakeImmutable([
234234
# The input can be one of the following:
235235
# - AUTODOC_FormatDate(rec), where <rec> is a record with entries year, month, day;
236236
# - AUTODOC_FormatDate(year[, month[, day]])
237+
# - AUTODOC_FormatDate(date_str) where date_str is a string of the form "DD/MM/YYYY" or "YYYY-MM-DD"
237238
# In each case, the year, month or day may be given as either an
238239
# integer, or as a string representing an integer.
239240
InstallGlobalFunction( AUTODOC_FormatDate,
240241
function(arg)
241242
local date, key, val, result;
242243
if Length(arg) = 1 and IsRecord(arg[1]) then
243244
date := ShallowCopy(arg[1]);
245+
elif Length(arg) = 1 and IsString(arg[1]) then
246+
if Length(arg[1]) = 10 then
247+
date := arg[1];
248+
if date{[3,6]} = "//" then
249+
date := rec(
250+
day := Int(date{[1,2]}),
251+
month := Int(date{[4,5]}),
252+
year := Int(date{[7..10]}),
253+
);
254+
elif date{[5,8]} = "--" then
255+
date := rec(
256+
year := Int(date{[1..4]}),
257+
month := Int(date{[6,7]}),
258+
day := Int(date{[9,10]}),
259+
);
260+
else
261+
Unbind(date);
262+
fi;
263+
fi;
244264
elif Length(arg) in [1..3] then
245265
date := rec();
246266
date.year := arg[1];

tst/misc.tst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ gap> AUTODOC_FormatDate(2019, 3, 1);
2626
"1 March 2019"
2727
gap> AUTODOC_FormatDate("2019", "3", "1");
2828
"1 March 2019"
29+
gap> AUTODOC_FormatDate("2019-03-01");
30+
"1 March 2019"
31+
gap> AUTODOC_FormatDate("01/03/2019");
32+
"1 March 2019"
2933
gap> AUTODOC_FormatDate(rec(year:=2019));
3034
"2019"
3135
gap> AUTODOC_FormatDate(rec(year:=2019, month:=3));

0 commit comments

Comments
 (0)