Skip to content

Commit

Permalink
Makes comparison between TZ naive UTC dates
Browse files Browse the repository at this point in the history
- push to v0.1.9
  • Loading branch information
Giulio Gratta committed Nov 17, 2017
1 parent 8a0c322 commit cd0bfc7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
30 changes: 15 additions & 15 deletions freetextresponse/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
Mixins for the Free Text Response XBlock
"""
import datetime
import pytz
from django.conf import settings

TIME_ZONE = pytz.timezone(getattr(settings, 'TIME_ZONE', pytz.utc.zone))


class EnforceDueDates(object): # pylint: disable=too-few-public-methods
Expand All @@ -15,19 +11,23 @@ class EnforceDueDates(object): # pylint: disable=too-few-public-methods
subsection in which they are placed
"""

# These values are pulled from platform.
# They are defaulted to None for tests.
due = None
graceperiod = None

def is_past_due(self):
"""
Determine if component is past-due
"""
now = datetime.datetime.utcnow().replace(tzinfo=TIME_ZONE)
if self.due is not None:
due_date = self.due
if self.graceperiod is not None:
due_date = due_date + self.graceperiod
return now > due_date
# These values are pulled from platform.
# They are defaulted to None for tests.
due = getattr(self, 'due', None)
graceperiod = getattr(self, 'graceperiod', None)
# Calculate the current DateTime so we can compare the due date to it.
# datetime.utcnow() returns timezone naive date object.
now = datetime.datetime.utcnow()
if due is not None:
# Remove timezone information from platform provided due date.
# Dates are stored as UTC timezone aware objects on platform.
due = due.replace(tzinfo=None)
if graceperiod is not None:
# Compare the datetime objects (both have to be timezone naive)
due = due + graceperiod
return now > due
return False
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "xblock-free-text-response",
"title": "FreeTextResponse XBlock",
"description": "Enables instructors to create questions with free-text responses.",
"version": "0.1.8",
"version": "0.1.9",
"homepage": "https://github.com/Stanford-Online/xblock-free-text-response",
"author": {
"name": "Azim Pradhan",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def run_tests(self):

setup(
name="xblock-free-text-response",
version="0.1.8",
version="0.1.9",
description="Enables instructors to create questions with free-text responses.",
license='AGPL-3.0',
packages=[
Expand Down

0 comments on commit cd0bfc7

Please sign in to comment.