<commit_before>/**
 * Returns an opportunity if:
 *  1. There is a birth fact
 *  2. There is a birth date
 *  3. There is a death fact
 *  4. There is a death date
 */
var utils = require('../util.js');

module.exports = {
  id: 'deathBeforeBirth',
  type: 'problem',
  title: 'Person Died Before They Were Born',
  signature: 'person',
  check: function(person) {

    var birth = person.$getBirth(),
        death = person.$getDeath();

    // If we don't have a birth
    if(!birth || !birth.date) {
      return;
    }
    
    // If we don't have a death
    if(!death || !death.date) {
      return;
    }

    // If either the birth or death date doesn't
    // have a formal value then we just compare years
    if(!birth.$getFormalDate() || !death.$getFormalDate()){
      if(utils.getFactYear(death) >= utils.getFactYear(birth)) {
        return;
      }
    }
    
    // If they both have formal values then do an exact comparison
    else if(utils.compareFormalDates(birth.$getFormalDate(), death.$getFormalDate()) !== 1) {
      return;
    }

    var descr = utils.markdown(function(){/*
        Go to [FamilySearch](https://familysearch.org/tree/#view=ancestor&person={{pid}}) and update the person.

        ## Help
    
        * [Correcting information in the Family Tree](https://familysearch.org/ask/productSupport#/Adding-and-Correcting-Information-about-People-and-Relationships)
        * [Explaining approximate birth dates](https://familysearch.org/ask/productSupport#/Do-not-know-exact-birth-date-or-death-date)
      */}, {pid:  person.id});

    return {
      id: this.id + ':' + person.id,
      type: this.type,
      title: this.title,
      description: descr,
      person: person,
      findarecord: undefined,
      gensearch: undefined
    };
  }
};<commit_msg>Better description for deathBeforeBirth; closes #59<commit_after>/**
 * Returns an opportunity if:
 *  1. There is a birth fact
 *  2. There is a birth date
 *  3. There is a death fact
 *  4. There is a death date
 */
var utils = require('../util.js');

module.exports = {
  id: 'deathBeforeBirth',
  type: 'problem',
  title: 'Person Died Before They Were Born',
  signature: 'person',
  check: function(person) {

    var birth = person.$getBirth(),
        death = person.$getDeath();

    // If we don't have a birth
    if(!birth || !birth.date) {
      return;
    }
    
    // If we don't have a death
    if(!death || !death.date) {
      return;
    }

    // If either the birth or death date doesn't
    // have a formal value then we just compare years
    if(!birth.$getFormalDate() || !death.$getFormalDate()){
      if(utils.getFactYear(death) >= utils.getFactYear(birth)) {
        return;
      }
    }
    
    // If they both have formal values then do an exact comparison
    else if(utils.compareFormalDates(birth.$getFormalDate(), death.$getFormalDate()) !== 1) {
      return;
    }

    var descr = utils.markdown(function(){/*
        A person cannot die before they were born. Visit [{{name}}](https://familysearch.org/tree/#view=ancestor&person={{pid}})
        in the Family Tree and fix the issue by doing one of the following:
        
        * Change the birth date to be before the death date
        * Change the death date to be after the birth date

        ## Help
    
        * [Correcting information in the Family Tree](https://familysearch.org/ask/productSupport#/Adding-and-Correcting-Information-about-People-and-Relationships)
        * [Explaining approximate birth dates](https://familysearch.org/ask/productSupport#/Do-not-know-exact-birth-date-or-death-date)
      */}, {
        pid: person.id,
        name: person.display.name
      });

    return {
      id: this.id + ':' + person.id,
      type: this.type,
      title: this.title,
      description: descr,
      person: person,
      findarecord: undefined,
      gensearch: undefined
    };
  }
};
{'fraction_non_alphanumeric': 0.1328045035823951, 'fraction_numerical': 0.0030706243602865915, 'mean_word_length': 2.5247971145175834, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3842582', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1182, 'n_words': 341}