Making date input more flexible

I recently imported a 1996 Brother’s Keeper GEDCOM to a blank tree to make an example Gramps tree that actually invites exploration.

It had hundreds of approximate dates in the format “yyyy/yy” which described a date range in the same century. Gramps saw most of those as Invalid dates. (Unfortunately, some were interpreted as valid Gregorian/Julian calendar entries.)

So, with Kari gently coaching me, here’s an example SuperTool (for v 1.2.5, released 17Oct2022) Events script that tweaks the “Selected” invalid date.

It is in “test flight” mode to start. The “Commit” is turned off and the actual “Set” line is commented. So Executing the script merely generates a list so you can visually confirm that the data is reformatting correctly. It has a “Safety” conditional which only allow the script to work on non-blank but invalid dates. And only for Events that are SELECTED in the Events view.

Make a backup before running ANY SuperTool script

Try it by creating a dummy Event with the Date “1767/68”. Select that event, run the SuperTool add-on and try the Script.

When the test flight is good, remove the “#” comment, select the “Commit changes” and Execute.

Reload the original script before changing the "my_reformatted_date = " line to slice & dice replicas of malformed dates in your Tree. (Simulate the bad formats in the Example.gramps tree for testing. DON’T develop formulas or test them on actual good Trees.)

I had to disable the “invalid” safety when I tweaked formulas for some bad dates that Gramps THOUGHT were good.

[Gramps SuperTool script file]
version=1

[title]
Invalid Date re-Formatter

[category]
Events

[initial_statements]
# Invalid Date re-Formatter.script 16Oct2022 v0.0.4  for SuperTool v1.2.5 
# Reformats invalid Event date ranges imported from Brother's Keeper v4.2 GEDCOM in the form YYYY/YY
# where the portion before the slash is a 4 digit beginning year. After the slash is a 2 digit ending year in the same century 
# found how to get the date in the 'Events with an invalid date' (v 1.0.8) add-on rule
#    https://github.com/Taapeli/isotammi-addons/tree/master/source/_hasvaliddate
# visually confirm that the reformatting makes a valid date string
from gramps.gen.datehandler import parser

[statements]
if not (event.get_date_object().get_text() == "" or event.get_date_object().is_valid()):
    my_date = event.get_date_object().get_text()
    my_reformatted_date = "bet " + my_date[ 0 : 4 ] + " and " + my_date[0:2] + my_date[-2:]
    dateval = parser.parse(my_reformatted_date)
    #event.set_date_object(dateval)

[filter]

[expressions]
type, participants, my_date, my_reformatted_date, dateval

[scope]
selected

[unwind_lists]
False

[commit_changes]
False

[summary_only]
False