Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

views: _api_occurrences: Support handling of timezone-aware datetime … #553

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions schedule/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,20 +351,11 @@ def _api_occurrences(start, end, calendar_slug, timezone):
if not start or not end:
raise ValueError("Start and end parameters are required")
# version 2 of full calendar
# TODO: improve this code with date util package
if "-" in start:

def convert(ddatetime):
if ddatetime:
ddatetime = ddatetime.split(" ")[0]
try:
return datetime.datetime.strptime(ddatetime, "%Y-%m-%d")
except ValueError:
# try a different date string format first before failing
return datetime.datetime.strptime(ddatetime, "%Y-%m-%dT%H:%M:%S")

return dateutil.parser.parse(ddatetime)
else:

def convert(ddatetime):
return datetime.datetime.utcfromtimestamp(float(ddatetime))

Expand All @@ -379,8 +370,8 @@ def convert(ddatetime):
elif settings.USE_TZ:
# If USE_TZ is True, make start and end dates aware in UTC timezone
utc = pytz.UTC
start = utc.localize(start)
end = utc.localize(end)
start = utc.localize(start) if start.tzinfo is None else start
end = utc.localize(end) if end.tzinfo is None else end

if calendar_slug:
# will raise DoesNotExist exception if no match
Expand Down