Skip to content

Commit

Permalink
Add normalisation to AddPackageInfos
Browse files Browse the repository at this point in the history
  • Loading branch information
wucas committed Aug 20, 2019
1 parent e5a30d6 commit 1451646
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions lib/package.gi
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ end );
#F AddPackageInfo( files )
##
BindGlobal( "AddPackageInfos", function( files, pkgdir, ignore )
local file, record, pkgname, version;
local file, record, pkgname, version, date, dd, mm;
for file in files do
# Read the `PackageInfo.g' file.
Unbind( GAPInfo.PackageInfoCurrent );
Expand Down Expand Up @@ -246,6 +246,33 @@ BindGlobal( "AddPackageInfos", function( files, pkgdir, ignore )
elif IsRecord( record.PackageDoc ) then
record.PackageDoc:= [ record.PackageDoc ];
fi;

#Normalize the format of 'Date', i.e. if it is the format yyyy-mm-dd
#then we change it to dd/mm/yyyy. When other tools have adapted to
#the yyyy-mm-dd format we can normalize to that format and at some
#point in the future get rid of this code.
if record.Date{ [5,8]} = "--" then
date := List( SplitString( record.Date, "-" ), Int);
Error("nach Split");
date := Permuted(date, (1,3)); #date = [dd,mm,yyyy]
#generate the day and month strings
#if the day has only one digit we have to add a 0
if date[1] < 10 then
dd := Concatenation("0", String(date[1]));
else
dd := String(date[1]);
fi;
#if the month has only one digit we have to add a 0
if date[2] < 10 then
mm := Concatenation("0", String(date[2]));
else
mm := String(date[2]);
fi;
Error("nach permuted");
record.Date := Concatenation(dd, "/", mm, "/", String(date[3]));
Error("nach neu");
fi;

if IsHPCGAP then
# FIXME: we make the package info record immutable, to
# allow access from multiple threads; but that in turn
Expand Down Expand Up @@ -2226,16 +2253,16 @@ InstallGlobalFunction( ValidatePackageInfo, function( info )
return true;
fi;
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]
date := List( SplitString( x, "-" ), Int);
date := 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;
return true;
end;
TestMandat( record, "Date",
x -> IsString(x) and CheckDateValidity(x), "a valid date");
Expand Down

0 comments on commit 1451646

Please sign in to comment.