Projet

Général

Profil

« Précédent | Suivant » 

Révision 954ab988

Ajouté par Benjamin Dauvergne il y a plus de 10 ans

humantime: all datetime objects are also date objects, to diffentiate them you must test for the former

Voir les différences:

entrouvert/djommon/humantime/utils.py
4 4

  
5 5
def datetime2human(dt, include_time=False, days_limit=7):
6 6
    '''Format a datetime object for human consumption'''
7
    if isinstance(dt, datetime.date):
7
    if isinstance(dt, datetime.datetime):
8
        time = dt.strftime('%H:%M')
9
    else:
8 10
        dt = datetime.datetime(year=dt.year, month=dt.month, day=dt.day)
9 11
        include_time = False
10
    else:
11
        time = dt.strftime('%H:%M')
12 12
    today = datetime.date.today()
13 13
    yesterday = today - datetime.timedelta(days=1)
14 14
    date = dt.date()

Formats disponibles : Unified diff