@@ -75,10 +75,10 @@ function getRecordYear(gx) {
75
75
// Ensure that anyone with an age has at least an estimated birth year.
76
76
// - First use an age from a qualifier on an event with a date.
77
77
// - Next use an age field and the date of the primary event, if any, or else the record date.
78
- // Also, REMOVE an estimated birth year (i.e., with "about" on date, and/or a PR_EST_BIR_DATE field)
79
- // when another birth event is also there.
78
+ // Also, REMOVE an estimated birth year (i.e., with "about" on date
79
+ // when another birth event with a non-'about' date is also there.
80
80
function updateEstimatedBirthYear ( gx ) {
81
- function countBirthFacts ( person ) {
81
+ function countBirthFactsWithDates ( person ) {
82
82
let numBirthFacts = 0 ;
83
83
for ( let fact of getList ( person , "facts" ) ) {
84
84
if ( fact . type && fact . type . endsWith ( "/Birth" ) && fact . date ) {
@@ -89,58 +89,68 @@ function updateEstimatedBirthYear(gx) {
89
89
}
90
90
91
91
function findEstimatedBirthFact ( facts ) {
92
- function hasLabelId ( fact , labelId ) {
93
- for ( let field of getList ( fact , "fields" ) ) {
94
- for ( let fieldValue of getList ( field . values ) ) {
95
- if ( fieldValue . labelId === labelId ) {
96
- return true ;
97
- }
98
- }
92
+ for ( let f = 0 ; f < facts . length ; f ++ ) {
93
+ let fact = facts [ f ] ;
94
+ if ( fact . type && fact . type . endsWith ( "/Birth" ) && fact . date && fact . date . original && fact . date . original . startsWith ( "about" ) ) {
95
+ return f ;
99
96
}
100
- return false ;
101
97
}
98
+ return - 1 ;
99
+ }
102
100
103
- for ( let f = 0 ; f < facts . length ; f ++ ) {
104
- let fact = facts [ f ] ;
105
- if ( fact . type && fact . type . endsWith ( "/Birth" ) && fact . date && fact . date . original && ! fact . place ) {
106
- if ( fact . date . original . startsWith ( "about" ) || hasLabelId ( fact , "PR_EST_BIR_DATE" ) ) {
107
- return f ;
101
+ function findBirthFactWithOnlyPlace ( person ) {
102
+ if ( person . facts ) {
103
+ for ( let fact of person . facts ) {
104
+ if ( fact . type === "http://gedcomx.org/Birth" && fact . place && ! fact . date ) {
105
+ return fact ;
108
106
}
109
107
}
110
108
}
111
- return - 1 ;
109
+ return null ;
112
110
}
113
111
114
112
function addEstimatedBirthFact ( person , birthYear ) {
115
113
if ( ! person . facts ) {
116
114
person . facts = [ ] ;
117
115
}
118
116
let estBirthYear = "about " + birthYear ;
119
- person . facts . push ( {
120
- "id" : generateLocalId ( "f_" ) ,
121
- "type" : "http://gedcomx.org/Birth" ,
122
- "date" : {
123
- "original" : estBirthYear
124
- }
125
- } ) ;
117
+ let placeOnlyBirthFact = findBirthFactWithOnlyPlace ( person ) ;
118
+ if ( placeOnlyBirthFact ) {
119
+ placeOnlyBirthFact . date = { "original" : estBirthYear } ;
120
+ }
121
+ else {
122
+ person . facts . push ( {
123
+ "id" : generateLocalId ( "f_" ) ,
124
+ "type" : "http://gedcomx.org/Birth" ,
125
+ "date" : {
126
+ "original" : estBirthYear
127
+ }
128
+ } ) ;
129
+ }
126
130
}
127
131
128
132
if ( ! gx ) {
129
133
return ;
130
134
}
131
135
let recordDate = getRecordYear ( gx ) ;
132
136
for ( let person of getList ( gx , "persons" ) ) {
133
- let numBirthFacts = countBirthFacts ( person ) ;
134
- if ( numBirthFacts === 0 ) {
137
+ let numBirthFactsWithDates = countBirthFactsWithDates ( person ) ;
138
+ if ( numBirthFactsWithDates === 0 ) {
135
139
let birthYear = estimateBirthYearFromPersonAge ( person , recordDate ) ;
136
140
if ( birthYear ) {
137
141
addEstimatedBirthFact ( person , birthYear ) ;
138
142
}
139
143
}
140
- else if ( numBirthFacts > 1 ) {
144
+ else if ( numBirthFactsWithDates > 1 ) {
141
145
let estimatedBirthFactIndex = findEstimatedBirthFact ( person . facts ) ;
142
146
if ( estimatedBirthFactIndex >= 0 ) {
143
- person . facts . splice ( estimatedBirthFactIndex , 1 ) ;
147
+ let fact = person . facts [ estimatedBirthFactIndex ] ;
148
+ if ( fact . place ) {
149
+ fact . date = null ;
150
+ }
151
+ else {
152
+ person . facts . splice ( estimatedBirthFactIndex , 1 ) ;
153
+ }
144
154
}
145
155
}
146
156
}
0 commit comments