Skip to content

Commit 66ab906

Browse files
committed
models.py: Extract time_to_string function
1 parent 84225dc commit 66ab906

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

naucse/models.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,14 @@ def merge_dict(base, patch):
317317
return result
318318

319319

320+
def time_from_string(time_string):
321+
hour, minute = time_string.split(':')
322+
hour = int(hour)
323+
minute = int(minute)
324+
tzinfo = dateutil.tz.gettz(_TIMEZONE)
325+
return datetime.time(hour, minute, tzinfo=tzinfo)
326+
327+
320328
class Session(Model):
321329
"""An ordered collection of materials"""
322330
def __init__(self, root, path, base_course, info, index, course=None):
@@ -471,12 +479,7 @@ def end_date(self):
471479
def _default_time(self, key):
472480
default_time = self.info.get('default_time')
473481
if default_time:
474-
time_string = default_time[key]
475-
hour, minute = time_string.split(':')
476-
hour = int(hour)
477-
minute = int(minute)
478-
tzinfo = dateutil.tz.gettz(_TIMEZONE)
479-
return datetime.time(hour, minute, tzinfo=tzinfo)
482+
return time_from_string(default_time[key])
480483
return None
481484

482485
@reify

0 commit comments

Comments
 (0)