RE: detecting GEDCOM dates with a year and a month but no day

[email protected] ("John Washburn") Sun, 12 Apr 2009 23:49:25 -0500
Newsgroups perl.gedcom
Organization John Washburn
Message-ID <003b01c9bbf3$3afac5d0$b0f05170$@org>
Would this work?  It is a little more discriminating on the year matches.
Person 8 and 5 are deliberate errors in the data format.
It is hoped the verbose still is more clear.

#!/usr/bin/perl
use strict;
use warnings;
my $MonthPattern = "(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)";
my ($day, $month, $year);
my ($name, $date );
my $condition;
while (my $line = <DATA>) {
    chomp $line;
    ($name, $date ) = split(/:/, $line);
    $condition = 0;
	$day = "";
	$month = "";
	$year = "";

	if (defined $date)
	{
		# Date Pattern 1: 1 AUG 1923 or 15 aPr 95
		if ($date =~ m/^(\d\d?)\s+$MonthPattern\s+(\d{1,4})$/i)
		{
			$day = $1;
			$month = uc $2;
			$year = $3;
		};
		# Date Pattern 2: AUG 1923 or juN 95
		if ($date =~ m/^$MonthPattern\s+(\d{1,4})$/i)
		{
			$month = uc $1;
			$year = $2;
			$condition = 1;
		};
		# Date Pattern 3: 1923 or  9
		if ($date =~ m/^(\d{1,4})$/i)
		{
			$year = $1;
		};

		# what should the condition be?
		if ($condition) {
			print "ERROR: For $name the date, [$date], has month
and year but no day: $date\n";
		}
		else
		{
			print "$name transforms, [$date], to ($day $month
$year)\n"
		}
	}
}
__DATA__
Person1:FEB 1978
Person2:1 APR 1917
Person3:JUL 1973
Person4:24 MAR 1964
Person5:ZZZ 1973
Person6:15 aPr 95
Person7:5 Jul 1995
Person8:15 June 1995
Person9:15 Jun 9
PersonA:15 Sep 999
PersonB:1999

-----Original Message-----
From: Philip Durbin [mailto:[email protected]] 
Sent: Wednesday, March 25, 2009 9:30 PM
To: Stephen Woodbridge
Cc: List - Gedcom
Subject: Re: detecting GEDCOM dates with a year and a month but no day

Yes, that works just fine.  Thanks!

Phil

On Mar 25, 2009, at 11:09 PM, Stephen Woodbridge wrote:

> This should work for the formats you show.
>
> if ($date =~ m/^\s*(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC) 
> \s+(\d+)\s*$/i) {
>    print "ERROR: date has month($1) and year($2) but no day: $date\n";
> }
>
> -Steve
>
> Philip Durbin wrote:
>> I'd like to detect when a date in my GEDCOM file contains a year  
>> and a month but no day, such as "FEB 1978".
>> I've written a small test (below) that you can run with "prove  
>> datebug.t".  The answer I'm looking for is the proper $condition  
>> for the if statement in datebug.pl (also below).
>> Gedcom::Date says "the Gedcom standard for genealogical data files  
>> defines a number of date formats" so it would be nice if the  
>> solution would work not just for the format my dates happen to use  
>> (i.e. 24 MAR 1964, which is what GRAMPS exported), but for any  
>> GEDCOM dates.  That said, I would (selfishly) be content with a  
>> solution that only works for dates like mine. :)
>> Thank you very much for your help!
>> Phil
>> [pdurbin@macbook tmp]$ cat datebug.pl
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>> while (my $line = <DATA>) {
>>    chomp $line;
>>    my ($name, $date ) = split(/:/, $line);
>>    # what should the condition be?
>>    my $condition;
>>    if ($condition) {
>>        print "ERROR: date has month and year but no day: $date\n";
>>    }
>> }
>> __DATA__
>> Person1:FEB 1978
>> Person2:1 APR 1917
>> Person3:JUL 1973
>> Person4:24 MAR 1964
>> [pdurbin@macbook tmp]$
>> [pdurbin@macbook tmp]$ cat datebug.t
>> use strict;
>> use warnings;
>> use Test::More tests => 1;
>> is(
>>  `./datebug.pl`,
>> "ERROR: date has month and year but no day: FEB 1978
>> ERROR: date has month and year but no day: JUL 1973\n",
>>  'datebug.pl is ok'
>> );
>> [pdurbin@macbook tmp]$
>