def marriageAfter14(husband, wife, family, repository): marriageDate = parseDate(family.getMarriageDate()) husbandBirthDate = parseDate(husband.getBirthDate()) wifeBirthDate = parseDate(wife.getBirthDate()) if relativedelta(marriageDate, husbandBirthDate).years < 14: raise Exceptions.MarriageBefore14(husband, family) if relativedelta(marriageDate, wifeBirthDate).years < 14: raise Exceptions.MarriageBefore14(wife, family)
def ageMorethan150(person, repository): birthDate = parseDate(person.getBirthDate()) deathDate = parseDate(person.getDeathDate()) if deathDate is not None and birthDate is not None and (relativedelta( deathDate, birthDate).years >= 150): raise Exceptions.AgeMorethan150(person) if deathDate is None and birthDate is not None and (relativedelta( datetime.today(), birthDate).years >= 150): raise Exceptions.AgeMorethan150(person)
def birthBfMarriageOfParents(husband, wife, family, repository): marriageDate = parseDate(family.getMarriageDate()) divorceDate = parseDate(family.getDivorceDate()) for cid in family.getChildrenIds(): child = repository.getPerson(cid) childBdate = parseDate(child.getBirthDate()) if marriageDate > childBdate: raise Exceptions.BirthBeforeMarriageOfParents(child, family) if divorceDate is not None and relativedelta(childBdate, divorceDate).months >= 9: raise Exceptions.BirthAfterDivorceOfParents(child, family)
def birthBeforeMarriage(husband, wife, family, repository): marriageDate = parseDate(family.getMarriageDate()) if marriageDate is None: return husbandBirthday = parseDate(husband.getBirthDate()) wifeBirthday = parseDate(wife.getBirthDate()) if husbandBirthday is None and wifeBirthday is None: return if husbandBirthday is not None and husbandBirthday > marriageDate: raise Exceptions.MarriageBeforeBirth(husband, family) if wifeBirthday is not None and wifeBirthday > marriageDate: raise Exceptions.MarriageBeforeBirth(wife, family)
def divorceBeforeDeath(husband, wife, family, repository): divorceDate = parseDate(family.getDivorceDate()) if divorceDate is None: return husbandDeathDate = parseDate(husband.getDeathDate()) wifeDeathDate = parseDate(wife.getDeathDate()) if husbandDeathDate is None and wifeDeathDate is None: return if husbandDeathDate is not None and husbandDeathDate < divorceDate: raise Exceptions.DivorceAfterDeath(husband, family) if wifeDeathDate is not None and wifeDeathDate < divorceDate: raise Exceptions.DivorceAfterDeath(wife, family) return
def marriageBeforeDeath(husband, wife, family, repository): marriageDate = parseDate(family.getMarriageDate()) if marriageDate is None: return husbandDeathDate = parseDate(husband.getDeathDate()) wifeDeathDate = parseDate(wife.getDeathDate()) if husbandDeathDate is None and wifeDeathDate is None: return if husbandDeathDate is not None and husbandDeathDate < marriageDate: raise Exceptions.MarriageAfterDeath(husband, family) if wifeDeathDate is not None and wifeDeathDate < marriageDate: raise Exceptions.MarriageAfterDeath(wife, family) return
def recentBirths(repository): table = PrettyTable() table.field_names = ["ID", "Name", "Birth Date"] for person in repository.getPeople(): if person.getBirthDate() is not None and (datetime.today() - timedelta( days=30)) <= parseDate(person.getBirthDate()) and parseDate( person.getBirthDate()) <= datetime.today(): table.add_row( [person.getIndiId(), person.getName(), person.getBirthDate()]) print('US35: List of recently born people') print(table)
def birthBeforeParentDeath(person, repository): famId = person.getChildFamilyId() if famId is not None: family = repository.getFamily(famId) father = repository.getPerson(family.getHusbandId()) mother = repository.getPerson(family.getWifeId()) fatherDeathDate = parseDate(father.getDeathDate()) motherDeathDate = parseDate(mother.getDeathDate()) childBirthDate = parseDate(person.getBirthDate()) if (fatherDeathDate is not None) and relativedelta( childBirthDate, fatherDeathDate).months >= 9: raise Exceptions.BirthOver9MonthsAfterFatherDeath( person, father.getDeathDate()) elif (motherDeathDate is not None) and childBirthDate > motherDeathDate: raise Exceptions.BirthAfterMotherDeath(person, mother.getDeathDate())
def recentDeadPeople(repository): recentDeathTable = PrettyTable() recentDeathTable.field_names = ["ID", "Name", "Death Date"] for person in repository.getPeople(): if person.getDeathDate() is not None and ( datetime.today() - timedelta(days=30)) <= parseDate( person.getDeathDate()) <= datetime.today(): recentDeathTable.add_row( [person.getIndiId(), person.getName(), person.getDeathDate()]) print('US36: List of recently dead prople') print(recentDeathTable)
def upcomingBirthdays(repository): upcomingBirthdayTable = PrettyTable() upcomingBirthdayTable.field_names = ["ID", "Name", "Birth Date"] for person in repository.getPeople(): birthDate = parseDate(person.getBirthDate()) currentYear = datetime.now().year birthDate = str(birthDate.day) + " " + str( birthDate.month) + " " + str(currentYear) birthDate = datetime.strptime(birthDate, '%d %m %Y') if person.getBirthDate() is not None and (datetime.today( )) <= birthDate <= (datetime.today() + timedelta(days=30)): upcomingBirthdayTable.add_row( [person.getIndiId(), person.getName(), person.getBirthDate()]) print('US38: List of upcoming birthdays') print(upcomingBirthdayTable)
def deathInFuture(person, repository): if person.getDeathDate() is not None: if inFuture(parseDate(person.getDeathDate())): raise Exceptions.DeathInFuture(person)
def birthInFuture(person, repository): if inFuture(parseDate(person.getBirthDate())): raise Exceptions.BirthInFuture(person)
def birthBeforeDeath(person, repository): birthDate = parseDate(person.getBirthDate()) deathDate = parseDate(person.getDeathDate()) if deathDate is not None and birthDate is not None and birthDate > deathDate: raise Exceptions.BirthAfterDeath(person)
def marriageBeforeDivorce(husband, wife, family, repository): marriageDate = parseDate(family.getMarriageDate()) divorceDate = parseDate(family.getDivorceDate()) if divorceDate is not None and marriageDate is not None and marriageDate > divorceDate: raise Exceptions.MarriageAfterDivorce(husband, family)
def divorceInFuture(husband, wife, family, repository): if family.getDivorceDate() is not None: if inFuture(parseDate(family.getDivorceDate())): raise Exceptions.DivorceInFuture(husband, family)
def marriageInFuture(husband, wife, family, repository): if inFuture(parseDate(family.getMarriageDate())): raise Exceptions.MarriageInFuture(husband, family)