Skip to content

Commit

Permalink
Merge pull request #230 from baxeico/develop
Browse files Browse the repository at this point in the history
Make start and end dates aware only if USE_TZ=True in django settings
  • Loading branch information
llazzaro authored Jul 28, 2016
2 parents 5b8fef1 + e7231e3 commit a41a14b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions schedule/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.views.generic.edit import (
UpdateView, CreateView, DeleteView, ModelFormMixin, ProcessFormView)
from django.utils.http import is_safe_url
from django.conf import settings

from schedule.conf.settings import (GET_EVENTS_FUNC, OCCURRENCE_CANCEL_REDIRECT,
EVENT_NAME_PLACEHOLDER, CHECK_EVENT_PERM_FUNC,
Expand Down Expand Up @@ -305,7 +306,7 @@ def api_occurrences(request):


def _api_occurrences(start, end, calendar_slug):
utc = pytz.UTC

if not start or not end:
raise ValueError('Start and end parameters are required')
# version 2 of full calendar
Expand All @@ -319,8 +320,14 @@ def convert(ddatetime):
def convert(ddatetime):
return datetime.datetime.utcfromtimestamp(float(ddatetime))

start = utc.localize(convert(start))
end = utc.localize(convert(end))
start = convert(start)
end = convert(end)
# If USE_TZ is True, make start and end dates aware in UTC timezone
if settings.USE_TZ:
utc = pytz.UTC
start = utc.localize(start)
end = utc.localize(end)

if calendar_slug:
# will raise DoesNotExist exception if no match
calendars = [Calendar.objects.get(slug=calendar_slug)]
Expand Down

0 comments on commit a41a14b

Please sign in to comment.