Skip to content

Commit

Permalink
ValidatePackageInfo accepts date format yyyy-mm-dd
Browse files Browse the repository at this point in the history
If the date format is dd/mm/yyyy and InfoLevel InfoPackageLoading
is set to at least 2 it prints a hint to change the format.

Add validity check for dates

Update relevant testfile

Fixes #2727
  • Loading branch information
Lucas Wollenhaupt authored and wucas committed Mar 20, 2019
1 parent 38aa4e8 commit e9ea8fc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
39 changes: 35 additions & 4 deletions lib/package.gi
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,7 @@ InstallGlobalFunction( DeclareAutoreadableVariables,
InstallGlobalFunction( ValidatePackageInfo, function( info )
local record, pkgdir, i, IsStringList, IsRecordList, IsProperBool, IsURL,
IsFilename, IsFilenameList, result, TestOption, TestMandat, subrec,
list;
list, date, CheckDateValidity;

if IsString( info ) then
if IsReadableFile( info ) then
Expand Down Expand Up @@ -2203,9 +2203,40 @@ InstallGlobalFunction( ValidatePackageInfo, function( info )
x -> IsString(x) and 0 < Length(x) and x[1] <> '=',
"a nonempty string that does not start with `='" );
TestMandat( record, "Date",
x -> IsString(x) and Length(x) = 10 and x{ [3,6] } = "//"
and ForAll( x{ [1,2,4,5,7,8,9,10] }, IsDigitChar ),
"a string of the form `dd/mm/yyyy'" );
x -> IsString(x) and Length(x) = 10
and ( ( x{ [3,6] } = "//" and ForAll( x{ [1,2,4,5,7,8,9,10] }, IsDigitChar ) )
or ( x{ [5,8] } = "--" and ForAll( x{ [1,2,3,4,6,7,9,10] }, IsDigitChar ) ) ) ,
"a string of the form `yyyy-mm-dd` or `dd/mm/yyyy`" );

#If the date is in the format `dd/mm/yyyy` a message is printed
if IsBound( record.Date ) and record.Date{ [3,6] } = "//" then
Info( InfoPackageLoading, 2, Concatenation(record.PackageName, ": Please be adviced to change the date format to `yyyy-mm-dd`"));
fi;

#check if the date is valid
CheckDateValidity := function(x)
if x{ [3,6] } = "//" then
date := List( SplitString( x, "/" ), Int);
if not (date[1] in [1..31] and
date[2] in [1..12] and
date[3] > 1999 and # GAP 4 appeared in 1999
date[1] <= DaysInMonth( date[2], date[3] )) then
return false;
fi;
elif x{ [5,8] } = "--" then
date := List( SplitString( date, "-" ), Int);
if not (date[3] in [1..31] and
date[2] in [1..12] and
date[1] > 1999 and # GAP 4 appeared in 1999
date[3] <= DaysInMonth( date[2], date[1] )) then
return false;
fi;
fi;
return true;
end;
TestMandat( record, "Date",
x -> IsString(x) and CheckDateValidity(x), "a valid date");

TestOption( record, "License",
x -> IsString(x) and 0 < Length(x),
"a nonempty string containing an SPDX ID" );
Expand Down
4 changes: 3 additions & 1 deletion tst/testinstall/package.tst
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ gap> ValidatePackageInfo(rec());
#E component `Subtitle' must be bound to a string
#E component `Version' must be bound to a nonempty string that does not start\
with `='
#E component `Date' must be bound to a string of the form `dd/mm/yyyy'
#E component `Date' must be bound to a string of the form `yyyy-mm-dd` or `dd\
/mm/yyyy`
#E component `Date' must be bound to a valid date
#E component `ArchiveURL' must be bound to a string started with http://, htt\
ps:// or ftp://
#E component `ArchiveFormats' must be bound to a string
Expand Down

0 comments on commit e9ea8fc

Please sign in to comment.