Updating age by plug-in
Posted: 18 Feb 2018 17:47
FTM has no specific field for recording ages in event entries, so I have a huge number of ages recorded as NOTEs that I wish to convert to "proper" ages within FH. The format is very consistent, either just "age xxx" or "other comment, age xxx", so a plug-in is the obvious way to go.
I have code that does what I need, but the problem comes when the age is not a valid GEDCOM age (e.g. "5½", "6 weeks", etc.). When the age is set with fhSetValueAsText(ptAge, strAge), FH does the same type of "adjusting" as when similar text is entered directly into the Property Box, so the examples above become "5y" and "6y", respectively. This behaviour is fine when you can see the result directly, but totally unacceptable when it is happening blindly, as when a plug-in is running.
There is no difference in the return value of the fhSetValueAsText() function, as this is a general function and the argument presented is valid text, but neither is it returning any internal flag within the program to say that the text has been modified.
At the moment, my pattern matching to extract the age is relatively unconstrained (strAge = string.match(strNote, "^age (.+)$") and strNewNote, strAge = string.match(strNote, "^(.+), age (.+)$") for the two alternative forms given above). My first thought is to modify the pattern matching so it only takes valid GEDCOM ages (conservatively, an integer optionally followed by a single 'y', 'm', or 'd'), but this feels a little like a workaround. Is there a way of alerting the user to the fact that FH is making assumptions and changing data, or is it down to the plug-in writer ensure that only clean and valid data are presented to the program?
I have code that does what I need, but the problem comes when the age is not a valid GEDCOM age (e.g. "5½", "6 weeks", etc.). When the age is set with fhSetValueAsText(ptAge, strAge), FH does the same type of "adjusting" as when similar text is entered directly into the Property Box, so the examples above become "5y" and "6y", respectively. This behaviour is fine when you can see the result directly, but totally unacceptable when it is happening blindly, as when a plug-in is running.
There is no difference in the return value of the fhSetValueAsText() function, as this is a general function and the argument presented is valid text, but neither is it returning any internal flag within the program to say that the text has been modified.
At the moment, my pattern matching to extract the age is relatively unconstrained (strAge = string.match(strNote, "^age (.+)$") and strNewNote, strAge = string.match(strNote, "^(.+), age (.+)$") for the two alternative forms given above). My first thought is to modify the pattern matching so it only takes valid GEDCOM ages (conservatively, an integer optionally followed by a single 'y', 'm', or 'd'), but this feels a little like a workaround. Is there a way of alerting the user to the fact that FH is making assumptions and changing data, or is it down to the plug-in writer ensure that only clean and valid data are presented to the program?