X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/8d1372958ce4a205f11fcdd44cf6e9cac8429a69..62d83af2cafb15b3940311cf305a30d489909d95:/apps/pdcounter/templatetags/time_tags.py diff --git a/apps/pdcounter/templatetags/time_tags.py b/apps/pdcounter/templatetags/time_tags.py index 1d4f23a93..e454acd6b 100755 --- a/apps/pdcounter/templatetags/time_tags.py +++ b/apps/pdcounter/templatetags/time_tags.py @@ -8,9 +8,15 @@ from django.utils import timezone register = template.Library() @register.filter -def local_to_utc(localtime): - if isinstance(localtime, datetime.date): - localtime = datetime.datetime.combine(localtime, datetime.time(0,0)) +def date_to_utc(date, day_end=False): + """ Converts a datetime.date to UTC datetime. + + The datetime represents the start (or end) of the given day in + the server's timezone. + """ + if day_end: + date += datetime.timedelta(1) + localtime = datetime.datetime.combine(date, datetime.time(0,0)) return timezone.utc.normalize( pytz.timezone(settings.TIME_ZONE).localize(localtime) )