Files
edx-platform/common/lib/xmodule/xmodule/timeinfo.py
Don Mitchell cb40e9ff88 Fix a few remaining tz naive dates
And remove redundant but != date parsing methods. In process make
the general parsing function less lenient (don't default date nor
month)
2013-06-17 13:26:45 -04:00

34 lines
1.2 KiB
Python

import logging
from xmodule.fields import Timedelta
log = logging.getLogger(__name__)
class TimeInfo(object):
"""
This is a simple object that calculates and stores datetime information for an XModule
based on the due date and the grace period string
So far it parses out three different pieces of time information:
self.display_due_date - the 'official' due date that gets displayed to students
self.grace_period - the length of the grace period
self.close_date - the real due date
"""
_delta_standin = Timedelta()
def __init__(self, due_date, grace_period_string):
if due_date is not None:
self.display_due_date = due_date
else:
self.display_due_date = None
if grace_period_string is not None and self.display_due_date:
try:
self.grace_period = TimeInfo._delta_standin.from_json(grace_period_string)
self.close_date = self.display_due_date + self.grace_period
except:
log.error("Error parsing the grace period {0}".format(grace_period_string))
raise
else:
self.grace_period = None
self.close_date = self.display_due_date