Projet

Général

Profil

0001-utils-add-method-to-convert-datetime-to-UTC-and-to-x.patch

Benjamin Dauvergne, 04 décembre 2015 19:34

Télécharger (1,28 ko)

Voir les différences:

Subject: [PATCH 1/2] utils: add method to convert datetime to UTC and to
 xs:datetime strings (using UTC timezone) (#9141)

 src/authentic2/utils.py | 9 +++++++++
 1 file changed, 9 insertions(+)
src/authentic2/utils.py
21 21
from django import forms
22 22
from django.forms.util import ErrorList
23 23
from django.forms.utils import to_current_timezone
24
from django.utils import timezone
24 25
from django.utils import html, http
25 26
from django.utils.translation import ugettext as _
26 27
from django.shortcuts import resolve_url
......
616 617
    else:
617 618
        messages.warning(request, _('No user to switch back to'))
618 619
    return continue_to_next_url(request)
620

  
621
def datetime_to_utc(dt):
622
    if timezone.is_naive(dt):
623
        dt = timezone.make_aware(dt)
624
    return dt.astimezone(timezone.utc)
625

  
626
def datetime_to_xs_datetime(dt):
627
    return datetime_to_utc(dt).isoformat().split('.')[0] + 'Z'
619
-