From 750681f16e38345e013a16f952c51067e775fb07 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 Update relevant testfile Fixes #2727 --- lib/package.gi | 35 +++++++++++++++++++++++++++++++---- tst/testinstall/package.tst | 4 +++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/package.gi b/lib/package.gi index fcd62953dad..7bc93441d87 100644 --- a/lib/package.gi +++ b/lib/package.gi @@ -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 @@ -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" ); diff --git a/tst/testinstall/package.tst b/tst/testinstall/package.tst index 20c32d032c4..e5340e15394 100644 --- a/tst/testinstall/package.tst +++ b/tst/testinstall/package.tst @@ -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