def from_str(cls, time):
''' takes a string like 1h, 2m, and returns a time_period object '''
# let's compute some sane things from these
time_period = cls()
if time == 'today':
time_period.hours = int(dt.now(tzlocal.get_localzone()).hour)
return time_period
if time.lower().endswith(('h', 'm')) and time[:-1].isdigit():
qualifier, time = time[-1].lower(), int(time[:-1])
if qualifier == 'h':
time_period.time_str = 'Hour' if time == 1 else 'Hours'
time_period.hours = time
if qualifier == 'm':
time_period.time_str = 'Minutes'
time_period.minutes = time if time >= 5 else 5
return time_period
评论列表
文章目录