1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
7 from django.conf import settings
8 from django import template
9 from django.utils import timezone
12 register = template.Library()
15 def date_to_utc(date, day_end=False):
16 """ Converts a datetime.date to UTC datetime.
18 The datetime represents the start (or end) of the given day in
19 the server's timezone.
22 date += datetime.timedelta(1)
23 localtime = datetime.datetime.combine(date, datetime.time(0, 0))
24 return timezone.utc.normalize(
25 pytz.timezone(settings.TIME_ZONE).localize(localtime)
31 return dt.strftime('%Y/%m/%d %H:%M:%S UTC')