Project

General

Profile

« Previous | Next » 

Revision 954ab988

Added by Benjamin Dauvergne over 10 years ago

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

View differences:

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()

Also available in: Unified diff