Good evening! I'm a lawyer and I often have to calculate how long until sentenced people will be able to reach benefits, like parole.

It works like this:

First, I need to get some main variables, like the day that person started serving the sentence (the day he was arrested). This will be a base date for the first benefit. Lets say someone was arrested at 12 November 2014.

```
base_date = datetime.date(day=12, month=11, year=2014)

```

The second thing I have to do is to know what was the sentence for each crime (sometimes the person is convicted for more than one crime and, for each of them, there is a different calcule for the benefit. Let's say this person was convicted for two crimes:

* For the first crime (which is a more serious crime), he was sentenced for 7 years and 4 months in jail.
* For the second crime, he was sentenced for 4 years, 10 months and 20 days in jail.

In order to do that, I used this method and this is where I think my code fails. I believe these variables should be in a datetime method, or something like that.

`pena1_years, pena1_months, pena1_days = 7, 4, 0`

`pena2_years, pena2_months, pena2_days = 4, 10, 20`

Now, as the first crime is more serious, he will need to serve 2/5 of that sentence plus 1/6 of his second sentence to be able to reach his first benefit. The result of both should be added to base\_date, in order to know when he will be able to reach the first benefit. I transformed everything into days.

```
pena1_total = int(((pena1_years * 365) + (pena1_months * 30) + (pena1_days)) / 5 * 2)
datedifference1 = datetime.datetime.now() - datetime.timedelta(days=pena1_total)
pena1_total = relativedelta(datetime.datetime.now(), datedifference1)
print("Pena 1: " + str(pena1_total.years) + "a, " + str(pena1_total.months) + "m, " + str(pena1_total.days) + "d.")

```

(Print returned this: Pena 1: 2a, 11m, 4d.)

```
pena2_total = int(((pena2_years * 365) + (pena2_months * 30) + (pena2_days)) / 6)
datedifference2 = datetime.datetime.now() - datetime.timedelta(days=pena2_total)
pena2_total = relativedelta(datetime.datetime.now(), datedifference2)
print("Pena 2: " + str(pena2_total.years) + "a, " + str(pena2_total.months) + "m, " + str(pena2_total.days) + "d.")

```

(Print returned this: Pena 2: 0a, 9m, 21d.)

After calculating the fractions for each crime, I'd need to sum both and then add to the base date. In this situation, this guy would have to serve 2 years, 11 months and 5 days for the first crime and 9 months and 23 days for the second one, in a total of 3 years, 8 months and 29 days before he can have his first benefit. However, I need to follow this rules (this is how the law says it must be calculated):

* Must use regular calendar (Gregorian);
* First, add up the years (2014 + 3 years = 2017);
* Then, add up the months (July 2018);
* Then, add up the days, but the first day he started serving must count (9 august 2018). It's important that the calendar is used when adding up the days, since the number of days in a month (and also depending on the year) may vary.

This is how I did it, but I'm not getting 9 august of 2018:

```
total = pena1_total + pena2_total
print("Total: " + str(total.years) + "a, " + str(total.months) + "m, " + str(total.days) + "d.")

```

(Print returned this: Total: 3a, 8m, 25d.)

```
data_semiaberto = data_base + relativedelta(days=+total.days, months=+total.months, years=+total.years)
print("Data para o semiaberto: " + str(data_semiaberto))

```

(Print returned this: Data para o semiaberto: 2018-08-06)

Then, the date for the first benefit will be the base date for his parole. He will need to serve another 2/5 of the remaining sentence for the first crime and 1/6 for the remaining sentence for the second crime. For this, I'd need to subtract what he served so far from the total sentence for each crime. However, I'm stuck here.

Here is the full code:

```
import datetime
from dateutil.relativedelta import relativedelta

data_base = datetime.date(day=12, month=11, year=2014)
pena1_years, pena1_months, pena1_days = 7, 4, 0
pena2_years, pena2_months, pena2_days = 4, 10, 20

def calculadora():
    # Fraction of the first sentence
    pena1_total = int(((pena1_years * 365) + (pena1_months * 30) + (pena1_days)) / 5 * 2)
    datedifference1 = datetime.datetime.now() - datetime.timedelta(days=pena1_total)
    pena1_total = relativedelta(datetime.datetime.now(), datedifference1)
    print("Pena 1: " + str(pena1_total.years) + "a, " + str(pena1_total.months) + "m, " + str(pena1_total.days) + "d.")

    # Fraction of the second sentence
    pena2_total = int(((pena2_years * 365) + (pena2_months * 30) + (pena2_days)) / 6)
    datedifference2 = datetime.datetime.now() - datetime.timedelta(days=pena2_total)
    pena2_total = relativedelta(datetime.datetime.now(), datedifference2)
    print("Pena 2: " + str(pena2_total.years) + "a, " + str(pena2_total.months) + "m, " + str(pena2_total.days) + "d.")

    # Fraction total
    total = pena1_total + pena2_total
    print("Total: " + str(total.years) + "a, " + str(total.months) + "m, " + str(total.days) + "d.")

    # Date of the first benefit.
    data_semiaberto = data_base + relativedelta(days=+total.days, months=+total.months, years=+total.years)
    print("Data para o semiaberto: " + str(data_semiaberto))
calculadora()

```

Could someone help me please? It'd save me a lot of time during work.