Calculate the age
    :param dob: datetime object
    :return: int
331927
def how_old(dob):
    
    today = datetime.date.today()
    return today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day))
938724
def generate_age(issue_time):
    """"""
    td = datetime.datetime.now() - issue_time
    age = (td.microseconds + (td.seconds + td.days * 24 * 3600)
           * 10 ** 6) / 10 ** 6
    return unicode_type(age)
705851
def add_years(datetime_like_object, n, return_date=False):
    
    a_datetime = parser.parse_datetime(datetime_like_object)

    # try assign year, month, day
    try:
        a_datetime = datetime(
            a_datetime.year + n, a_datetime.month, a_datetime.day,
            a_datetime.hour, a_datetime.minute, a_datetime.second,
            a_datetime.microsecond, tzinfo=a_datetime.tzinfo,
        )
    except ValueError:  # Must be xxxx-02-29
        a_datetime = datetime(
            a_datetime.year + n, 2, 28,
            a_datetime.hour, a_datetime.minute,
            a_datetime.second, a_datetime.microsecond)

    if return_date:  # pragma: no cover
        return a_datetime.date()
    else:
        return a_datetime
396890
def birthday(self):
        
        if isfile(self.pid_file):
            
            # Timestamp / timezone string
            tstamp  = datetime.fromtimestamp(self.created())
            tzone   = tzname[0] 
            weekday = WEEKDAY[tstamp.isoweekday()]
            
            # PID file age / age string
            age     = self.age()
            age_str = '{}s ago'.format(age[0]) 
            
            # Birthday string
            bday   = '{} {} {}; {}'.format(weekday, tstamp, tzone, age_str)
            
            # Return timestamp / timestamp string
            return (self.created(), bday)
        return (None, None)
268495
def age(self):
    """"""
    # TODO(user) move up to AFF4Object after some analysis of how .age is
    # used in the codebase.
    aff4_type = self.Get(self.Schema.TYPE)

    if aff4_type:
      return aff4_type.age
    else:
      # If there is no type attribute yet, we have only just been created and
      # not flushed yet, so just set timestamp to now.
      return rdfvalue.RDFDatetime.Now()
410385
private void checkJodaGetYear() {
        int COUNT = COUNT_VERY_FAST;
        DateTime dt = new DateTime(GJChronology.getInstance());
        for (int i = 0; i < AVERAGE; i++) {
            start("Joda", "getYear");
            for (int j = 0; j < COUNT; j++) {
                int val = dt.getYear();
                if (val == 0) {System.out.println("Anti optimise");}
            }
            end(COUNT);
        }
    }
822498
def agedepth(self, d):
        
        # TODO(brews): Function cannot handle hiatus
        # See lines 77 - 100 of hist2.cpp
        x = self.mcmcfit.sediment_rate
        theta0 = self.mcmcfit.headage  # Age abscissa (in yrs).  If array, dimension should be iterations or realizations of the sediment
        deltac = self.thick
        c0 = min(self.depth)  # Uniform depth segment abscissa (in cm).
        assert d > c0 or np.isclose(c0, d, atol = 1e-4)
        out = theta0.astype(float)
        i = int(np.floor((d - c0) / deltac))
        for j in range(i):
            out += x[j] * deltac
        ci = c0 + i * deltac
        assert ci < d or np.isclose(ci, d, atol = 1e-4)
        try:
            next_x = x[i]
        except IndexError:
            # Extrapolating
            next_x = x[i - 1]
        out += next_x * (d - ci)
        return out
422116
private void calculateYear()
  {
    long days = _dayOfEpoch;

    // shift to using 1601 as a base
    days += (1970 - 1601) * 365 + (1970 - 1601) / 4 - 3;

    long n400 = divFloor(days, 400 * 365 + 100 - 3);
    days -= n400 * (400 * 365 + 100 - 3);

    long n100 = divFloor(days, 100 * 365 + 25 - 1);
    if (n100 == 4)
      n100 = 3;
    days -= n100 * (100 * 365 + 25 - 1);

    long n4 = divFloor(days, 4 * 365 + 1);
    if (n4 == 25)
      n4 = 24;
    days -= n4 * (4 * 365 + 1);

    long n1 = divFloor(days, 365);
    if (n1 == 4)
      n1 = 3;

    _year = 400 * n400 + 100 * n100 + 4 * n4 + n1 + 1601;
    _dayOfYear = (int) (days - 365 * n1);

    _isLeapYear = isLeapYear(_year);
  }
380541
def convert_ages(Recs, data_model=3):
    
    if data_model == 3:
        site_key = 'site'
        agekey = "age"
        keybase = ""
    else:
        site_key = 'er_site_names'
        agekey = find('age', list(rec.keys()))
        if agekey != "":
            keybase = agekey.split('_')[0] + '_'

    New = []
    for rec in Recs:
        age = ''
        if rec[keybase + 'age'] != "":
            age = float(rec[keybase + "age"])
        elif rec[keybase + 'age_low'] != "" and rec[keybase + 'age_high'] != '':
            age = np.mean([rec[keybase + 'age_high'],
                           rec[keybase + "age_low"]])
            # age = float(rec[keybase + 'age_low']) + old_div(
            #    (float(rec[keybase + 'age_high']) - float(rec[keybase + 'age_low'])), 2.)
        if age != '':
            rec[keybase + 'age_unit']
            if rec[keybase + 'age_unit'] == 'Ma':
                rec[keybase + 'age'] = '%10.4e' % (age)
            elif rec[keybase + 'age_unit'] == 'ka' or rec[keybase + 'age_unit'] == 'Ka':
                rec[keybase + 'age'] = '%10.4e' % (age * .001)
            elif rec[keybase + 'age_unit'] == 'Years AD (+/-)':
                rec[keybase + 'age'] = '%10.4e' % ((2011 - age) * 1e-6)
            elif rec[keybase + 'age_unit'] == 'Years BP':
                rec[keybase + 'age'] = '%10.4e' % ((age) * 1e-6)
            rec[keybase + 'age_unit'] = 'Ma'
            New.append(rec)
        else:
            if 'site_key' in list(rec.keys()):
                print('problem in convert_ages:', rec['site_key'])
            elif 'er_site_name' in list(rec.keys()):
                print('problem in convert_ages:', rec['site_key'])
            else:
                print('problem in convert_ages:', rec)
        if len(New) == 0:
            print('no age key:', rec)
    return New
632365
public int calculateAge(Date birthday) {
        int result = -1;
        if (birthday != null) {
            GregorianCalendar todayCal = new GregorianCalendar();
            todayCal.setTime(new Date());
            int dayOfYear = todayCal.get(Calendar.DAY_OF_YEAR);
            int year = todayCal.get(Calendar.YEAR);
            GregorianCalendar birthdayCal = new GregorianCalendar();
            birthdayCal.setTime(birthday);
            int birthDayOfYear = birthdayCal.get(Calendar.DAY_OF_YEAR);
            int birthYear = birthdayCal.get(Calendar.YEAR);
            birthDayOfYear = 
                processLeapYear(todayCal, birthdayCal, birthDayOfYear);
            
            result = year - birthYear;
            if (dayOfYear < birthDayOfYear) {
                result--;
            }
        }
        return result;
    }
1254253
def work_experience(self, working_start_age: int = 22) -> int:
        
        age = self._store['age']
        if age == 0:
            age = self.age()

        return max(age - working_start_age, 0)
563
private function calculateAge(int $age): string
    {
        if ((int) ($age / 365.25) > 0) {
            $result = (int) ($age / 365.25) . 'y';
        } elseif ((int) ($age / 30.4375) > 0) {
            $result = (int) ($age / 30.4375) . 'm';
        } else {
            $result = $age . 'd';
        }

        return FunctionsDate::getAgeAtEvent($result);
    }
106638
def age_range(self):
        """"""
        if self.date_range is None:
            return None, None
        start_date = DateRange(self.date_range.start, self.date_range.start)
        end_date = DateRange(self.date_range.end, self.date_range.end)
        start_age = DOB(date_range=end_date).age
        end_age = DOB(date_range=start_date).age
        return start_age, end_age
963453
def get_age(dt):
        """"""
        delta = datetime.now() - dt
        days = delta.days
        hours, rem = divmod(delta.seconds, 3600)
        minutes, seconds = divmod(rem, 60)

        if days:
            return '%dd %dh %dm' % (days, hours, minutes)
        else:
            return '%dh %dm %ds' % (hours, minutes, seconds)
257883
def max_age(self):
        
        value = defines.OptionRegistry.MAX_AGE.default
        for option in self.options:
            if option.number == defines.OptionRegistry.MAX_AGE.number:
                value = int(option.value)
        return value
1034369
def age(self):
        
        
        # Created timestamp
        created = self.created()
        
        # Age in seconds / minutes / hours / days
        age_secs  = time() - created
        age_mins  = 0 if (age_secs < 60) else (age_secs / 60)
        age_hours = 0 if (age_secs < 3600) else (age_mins / 60)
        age_days  = 0 if (age_secs < 86400) else (age_hours / 24)
        
        # Return the age tuple
        return (
            int(age_secs), 
            int(age_mins), 
            int(age_hours), 
            int(age_days)
        )
732831
def age(self, now=None):
        
        if not self.time_created:
            return None
        if now is None:
            now = datetime.utcnow()
        return (now - self.time_created).seconds