This is NOT a software question but rather a rules questions.
How long can you be divorced before it is too late to "restart the clock" towards the 10 years necessary to qualify on the benefits of a divorced spouse? If you are married 9 years then divorced for two days then married for a year can you still get benefits? how about if divorrced for 1 month before remarying for a year ? 6 monthss then remarried for a year? When is the line that produces an irrevocable reset of the term?
How long do you have to be married to someone who dies before you qualify to receive under their benefits? Thats 9 months i believe (less if accidental death).
Example: The important point of the questions is to make certain someone never takes a chance of losing all social security benefits. 9 year long marriage ends in divorce followed immediately by marriage to another person but the new partner only lives for 8 months (less than the 9 required for widows benefits). So if the initial couple remarried right after the death are they automatically qualified for spousal survival benefits immediately (based on prior 9 years of marriage) or do they need to wait 9 months? And do they need to wait 10 years to qualify for divorce benefits or just 1 year to complete 10?
For divorced spousal benefits and surviving divorced spousal benefits, the claimant's marriage to the wage earner must have lasted for at least 10 consecutive years. The 10 year period can be interrupted by a divorce, as long as the couple remarried no later than during the calendar year immediately following the year in which their divorce was final.
For example, say Joan and Mike married on July 1 1980 and divorced on January 15 1987. As long as Joan and Mike remarry no later than December 31 1988, their marriage would be counted as uninterrupted for purposes of counting the 10 year duration of marriage requirement for divorced spousal benefits. So, as long as their remarriage lasts at least until July 1 1990, they would meet the 10 year requirement for divorced spousal benefits if they subsequently divorce again (https://secure.ssa.gov/apps10/poms.nsf/lnx/0300202005).
For widow's benefits, the widow's marriage to the wage earner must normally have lasted for at least 9 months leading up to the wage earner's death. There are exceptions to the 9 month duration of marriage requirement, though, including accidental deaths as you mentioned in your question. The 9 month duration requirement is also deemed to be met if a couple was previously married for at least 9 months, then divorce but remarry prior to the death of the wage earner. So, in your example the couple who remarried would meet the 9 month duration of marriage requirement for widow's benefits immediately upon their remarriage based on their prior 9 years of marriage (https://secure.ssa.gov/apps10/poms.nsf/lnx/0200305100). However, the prior 9 year marriage would only count toward the 10 year requirement for divorced spousal benefits if they remarried in the same calendar year as they divorced, or in the calendar year immediately following the year they divorced.