Skip to content

Commit

Permalink
Change plurality of dates in GEDCOM data
Browse files Browse the repository at this point in the history
It's not uncommon for individuals in GEDCOM to have multiple views of
the birthdate due to sources having entirely different dates or
different granularities of dates.
Also, when there is a collection of the same tags, the first one is
considered the "preferred" value. So pick that one most of the time.
  • Loading branch information
rafaelespinoza committed Jan 5, 2024
1 parent 9c20ed5 commit 43c32d9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
12 changes: 6 additions & 6 deletions internal/gedcom/gedcom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,26 +229,26 @@ func TestReadRecordsFields(t *testing.T) {
Names: []gedcom.PersonalName{
{Payload: "Charlie /Foxtrot/", Given: "Charlie", Nickname: "Chuck", Surname: "Foxtrot"},
},
Birth: &gedcom.Event{Date: mustParseDate(t, "1970-01-01")},
Death: &gedcom.Event{Date: mustParseDate(t, "2038-01-19")},
Birth: []*gedcom.Event{{Date: mustParseDate(t, "1970-01-01")}},
Death: []*gedcom.Event{{Date: mustParseDate(t, "2038-01-19")}},
FamiliesAsPartner: []string{"@F1@"},
},
{
Xref: "@I2@",
Names: []gedcom.PersonalName{
{Payload: "Charlene /Foxtrot/", Given: "Charlene", Nickname: "Y2K22", Surname: "Foxtrot"},
},
Birth: &gedcom.Event{Date: mustParseDate(t, "1970-01-01")},
Death: &gedcom.Event{Date: mustParseDate(t, "2022-01-01")},
Birth: []*gedcom.Event{{Date: mustParseDate(t, "1970-01-01")}},
Death: []*gedcom.Event{{Date: mustParseDate(t, "2022-01-01")}},
FamiliesAsPartner: []string{"@F1@"},
},
{
Xref: "@I3@",
Names: []gedcom.PersonalName{
{Payload: "Mike /Foxtrot/", Given: "Mike", Nickname: "Millennium Bug", Surname: "Foxtrot"},
},
Birth: &gedcom.Event{Date: mustParseDate(t, "1995-06-12")},
Death: &gedcom.Event{Date: mustParseDate(t, "2000-01-01")},
Birth: []*gedcom.Event{{Date: mustParseDate(t, "1995-06-12")}},
Death: []*gedcom.Event{{Date: mustParseDate(t, "2000-01-01")}},
Notes: []*gedcom.Note{
{Payload: `The year 2000 problem, also commonly known as the Y2K problem, Y2K scare, millennium bug, Y2K bug, Y2K glitch, Y2K error, or simply Y2K,
refers to potential computer errors related to the formatting and storage of calendar data for dates in and after the year 2000.`,
Expand Down
8 changes: 4 additions & 4 deletions internal/gedcom/individual_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type IndividualRecord struct {
Xref string
Names []PersonalName
Sex enumset.Sex
Birth *Event
Death *Event
Birth []*Event
Death []*Event
FamiliesAsChild []string // Xref IDs of families where the person is a child.
FamiliesAsPartner []string // Xref IDs of families where the person is a partner, such as a spouse.
SourceCitations []*SourceCitation
Expand Down Expand Up @@ -58,14 +58,14 @@ func parseIndividualRecord(ctx context.Context, i int, line *gedcom7.Line, subno
if err != nil {
log.Error(ctx, fields, err, "error parsing BIRT, skipping")
} else {
out.Birth = event
out.Birth = append(out.Birth, event)
}
case "DEAT":
event, err := parseEvent(ctx, subline, subnode.GetSubnodes())
if err != nil {
log.Error(ctx, fields, err, "error parsing DEAT, skipping")
} else {
out.Death = event
out.Death = append(out.Death, event)
}
case "SEX":
out.Sex = enumset.NewSex(subline.Payload)
Expand Down
14 changes: 9 additions & 5 deletions internal/srv/parse_gedcom.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ func convertGedcomPeople(ctx context.Context, records []*gedcom.IndividualRecord
if len(individual.Names) > 0 {
inputName = individual.Names[0]
}
if individual.Birth != nil {
birthdate, err = entity.NewDate(individual.Birth.Date, individual.Birth.DateRange)
// The GEDCOM7 spec says that unless otherwise specified (how to specify
// that is not specified), the first value in a collection is considered
// the preferred value. Just pick the first one, if available.
if len(individual.Birth) > 0 && individual.Birth[0] != nil {
birthdate, err = entity.NewDate(individual.Birth[0].Date, individual.Birth[0].DateRange)
if err != nil {
log.Error(ctx, map[string]any{"individual": individual}, err, "invalid Birth.Date")
log.Error(ctx, map[string]any{"individual": individual}, err, "invalid Birth")
return nil, err
}
}
if individual.Death != nil {
deathdate, err = entity.NewDate(individual.Death.Date, individual.Death.DateRange)

if len(individual.Death) > 0 && individual.Death[0] != nil {
deathdate, err = entity.NewDate(individual.Death[0].Date, individual.Death[0].DateRange)
if err != nil {
log.Error(ctx, map[string]any{"individual": individual}, err, "invalid Death.Date")
return nil, err
Expand Down

0 comments on commit 43c32d9

Please sign in to comment.