Commit b4e54e1c authored by Mathieu Giraud's avatar Mathieu Giraud Committed by Vidjil Team

vidjil_utils.py: age_months_years()

parent c3868935
......@@ -2,6 +2,7 @@ import math
import re
import defs
from gluon import current
from datetime import date
def format_size(n, unit='B'):
'''
......@@ -44,6 +45,25 @@ def format_size(n, unit='B'):
return fmt % size + ' ' + prefix + unit
def age_years_months(birth, months_below_year=4):
'''Get the age in years, and possibly months.'''
today = date.today()
years = today.year - birth.year - ((today.month, today.day) < (birth.month, birth.day))
age = '%dy' % years
if years >= months_below_year:
return age
months = today.month - birth.month - (today.day < birth.day)
if months < 0:
months += 12
age += ' %dm' % months
return age
def anon(patient_id, user_id):
db = current.db
auth=current.auth
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment