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 24e4534 commit 9ee7765
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions ged2site
Original file line number Diff line number Diff line change
Expand Up @@ -10260,23 +10260,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 9ee7765

Please sign in to comment.