Skip to content

Commit

Permalink
Reduce calls to date_parser_cached() in all_records_have_date()
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Nov 14, 2024
1 parent dce63bd commit af2adbf
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions gedcom
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,15 @@ foreach my $module (@needfull) {
$name =~ s{\.tar\.gz$}{}; # Remove file extension
$name =~ s{::(\d+)$}{ $1}; # Adjust version formatting if embedded in module name

eval "require $name" or die $@;
if($version) {
eval "require $name $version" or die $@;
} else {
eval "require $name" or die $@;
}
$name->import();

# Uncomment to check version if needed
# die "$name: need $version, got " . $name->VERSION if $version && $name->VERSION < $version;
die "$name: need $version, got " . $name->VERSION if $version && $name->VERSION < $version;
}

# use IPC::System::Simple;
Expand Down Expand Up @@ -8432,23 +8436,19 @@ sub all_records_have_date
my @records = @{$args{'records'}};
my $person = $args{'person'};

foreach my $record(@records) {
if((!ref($record)) || (ref($record) ne 'Gedcom::Record') || !$record->date()) {
return 0;
}
if(my $date = $record->date()) {
if(($date !~ /^\d/) || ($date =~ /[a-z]$/i) ||
($date =~ /[\/\-]/) || ($date =~ / to /) || !date_parser_cached(date => $date)) {
return 0;
}
if(!date_parser_cached(date => $date)) {
complain({
person => $person,
warning => "Record has an invalid date of $date"
});
return 0;
}
} else {
foreach my $record (@records) {
# Check if $record is an object and has a valid date method
return 0 unless(ref($record) && $record->can('date'));

my $date = $record->date();
# Check if the date is valid and matches required format
if((!defined $date) || ($date !~ /^\d/) || ($date =~ /[a-z]$/i) ||
($date =~ /[\/\-]/) || ($date =~ / to /) || !date_parser_cached(date => $date)) {
# Log a warning if date is invalid
complain({
person => $person,
warning => "Record has an invalid date of $date"
});
return 0;
}
}
Expand Down

0 comments on commit af2adbf

Please sign in to comment.