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 gap-system#2727
  • Loading branch information
Lucas Wollenhaupt authored and wucas committed Mar 21, 2019
1 parent 38aa4e8 commit 750681f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
35 changes: 31 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, CheckDateValidity;

if IsString( info ) then
if IsReadableFile( info ) then
Expand Down Expand Up @@ -2203,9 +2203,36 @@ 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)
local date;
if x{ [3,6] } = "//" then #for the old format split at '/'
date := List( SplitString( x, "/" ), Int);
elif x{ [5,8] } = "--" then #for the yyyy-mm-dd format split at '-'
date := List( SplitString( date, "-" ), Int);
Permuted(date, (1,3)); #sort such that date=[dd,mm,yyyy]
fi;
if IsBound(date) and (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;
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 750681f

Please sign in to comment.