frizbog / gedcom4j

Java library for reading/writing genealogy files in GEDCOM format
http://gedcom4j.org
53 stars 36 forks source link

BUG: validator complains about DEATH/AGE [PATCH] #193

Closed JPT77 closed 6 years ago

JPT77 commented 6 years ago

Hi I believe this is a bug since Gedcom 5.5 says

Codes in Event Date:
Some applications, such as Personal Ancestral File, pass key words as part of certain event dates.
Some of these key words were INFANT, CHILD, STILLBORN, etc. These have to do with being an
approximate age at an event.
In this version of GEDCOM, the information has been removed from the date value and specified by
an <AGE_AT_EVENT> key word value which indicates a descriptive age value at the time of the
enclosing event. (See <AGE_AT_EVENT>, page 37.) For example:
1 DEAT
2 DATE 13 MAY 1984
2 AGE STILLBORN
meaning this person died at age approximately 0 days old.
1 DEAT
2 DATE 13 MAY 1984
2 AGE INFANT
meaning this person died at age less than 1 year old.
Finding [fieldNameOfConcern=age, itemOfConcern=IndividualEvent 
[type=Birth, age=60, date=abt 1880, place=Place, ], severity=ERROR, 
problemCode=2, problemDescription=Value supplied is not allowed, ]
Finding [fieldNameOfConcern=age, itemOfConcern=IndividualEvent 
[type=Death, age=42, date=21 Mar 1921, place=Place, ], severity=ERROR, 
problemCode=2, problemDescription=Value supplied is not allowed, ]

ps. Age 60 at birth is wrong though :)

solved, patch

index fab08d4..c440ef4 100644
--- a/src/main/java/org/gedcom4j/validate/EventValidator.java
+++ b/src/main/java/org/gedcom4j/validate/EventValidator.java
@@ -184,7 +184,7 @@
         }
         String s = val.getValue().trim();
         for (String regex : AGE_FORMATS) {
-            if (regex.matches(s)) {
+            if (s.matches(regex)) {
                 return;
             }
         }
JPT77 commented 6 years ago

well, must by 60y but this does not work either.

JPT77 commented 6 years ago

patch for testcase

index e0afb62..86f5933 100644
--- a/src/test/java/org/gedcom4j/validate/IndividualEventValidatorTest.java
+++ b/src/test/java/org/gedcom4j/validate/IndividualEventValidatorTest.java
@@ -88,5 +88,13 @@
         e.getAddress().setCity("FryingPanVille");
         validator.validate();
         assertNoIssues();
+        
+        e = new IndividualEvent();
+        e.setType(IndividualEventType.DEATH);
+        i.getEvents().add(e);
+        e.setDate("05 may 1967");
+        e.setAge("STILLBORN"); // works
+        validator.validate();
+        assertNoIssues();

+        e.setAge("55y"); // fails
+        validator.validate();
+        assertNoIssues();
     }
 }

solved, see first comment