Projet

Général

Profil

« Précédent | Suivant » 

Révision 7b20f440

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

humantime: show datetime in the current timezone

Voir les différences:

entrouvert/djommon/humantime/utils.py
1 1
import datetime
2 2

  
3 3
from django.utils.translation import pgettext
4
from django.utils.timezone import localtime, get_default_timezone
4 5
from django.template.defaultfilters import date
5 6

  
6 7
def datetime2human(dt, include_time=False, days_limit=7):
......
8 9
    if isinstance(dt, datetime.datetime):
9 10
        time = dt.strftime('%H:%M')
10 11
    else:
11
        dt = datetime.datetime(year=dt.year, month=dt.month, day=dt.day)
12
        dt = datetime.datetime(year=dt.year, month=dt.month, day=dt.day,
13
                tzinfo=get_default_timezone())
12 14
        include_time = False
15
    dt = localtime(dt)
13 16
    today = datetime.date.today()
14 17
    yesterday = today - datetime.timedelta(days=1)
15 18
    subdate = dt.date()

Formats disponibles : Unified diff