Skip to content

Commit 1546ee8

Browse files
committed
Extend AUTODOC_FormatDate to deal with strings
... as used in the Date field of PackageInfo.g files.
1 parent 88e8e52 commit 1546ee8

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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)