From 1597a9960128a7ef5c9daa467ddaaa14fda34e7a Mon Sep 17 00:00:00 2001 From: Lucas Wollenhaupt Date: Tue, 19 Mar 2019 16:34:43 +0100 Subject: [PATCH] ValidatePackageInfo accepts date format yyyy-mm-dd 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 --- lib/package.gi | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/package.gi b/lib/package.gi index 9dbd5eea1f4..ea226e9f671 100644 --- a/lib/package.gi +++ b/lib/package.gi @@ -2118,7 +2118,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 @@ -2186,9 +2186,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"); + TestMandat( record, "ArchiveURL", IsURL, "a string started with http://, https:// or ftp://" ); TestMandat( record, "ArchiveFormats", IsString, "a string" ); TestOption( record, "TextFiles", IsStringList, "a list of strings" );