def test_time(self): c = Calendar() c = c.add(Day("came 9 left 15", today)) data = c.dump() c2 = Calendar.load(data) assert c2.days[today].came == time(9) assert c2.days[today].left == time(15)
def _to_time(cls, t: Union[time, timedelta, None]) -> Union[time, None]: if t is None: return None if isinstance(t, time): return t hour = t.seconds // 3600 minute = (t.seconds - hour * 3600) // 60 return time(hour=hour, minute=minute)
def as_time(cls, str_: str) -> Union[time, timedelta]: """Parses a string on the format specified below. If the string is not on the specified format, a TimeParserError is raised. :param str_: A string on the form H, HH:MM, H:MM, HHMM, HMM, M m, MM m, M min or MM min :return: a datetime.time or datetime.timedelta object corresponding to the input string """ hours, minutes = cls._to_hours_and_minutes(str_) return time(hour=hours, minute=minutes)
def test_basic(self): assert str(time(hour=7, minute=45)) == "07:45"
def test_overwrite_all(self): c = Calendar() c = c.add(Day("came 9 left 15", today)) c = c.add(Day("came 8 left 14", today)) assert c.days[today].came == time(8) assert c.days[today].left == time(14)
def test_add_to_day_inverse_order(self): c = Calendar() c = c.add(Day("left 15", today)) c = c.add(Day("came 9", today)) assert c.days[today].came == time(9) assert c.days[today].left == time(15)
def test_add_day(self): c = Calendar() c = c.add(Day("came 9 left 15", today)) assert c.days[today].came == time(9) assert c.days[today].left == time(15)
def test_to_timedelta(self): assert Day._to_timedelta(time( hour=5, minute=37)) == timedelta(seconds=5 * 3600 + 37 * 60)
def test_to_time(self): assert Day._to_time(timedelta(hours=5, minutes=37)) == time(hour=5, minute=37)