Beispiel #1
0
    def _assign_time_interactive(self, task, total):
        self._title("\n\nAssign Time")
        self._print("The stop watch recorded {}. Assign that time to the " "metrics in this task:\n\n".format(total))

        remainder = total
        duration_metrics = filter(lambda m: m.metric_type is Duration, self.current_project.metrics)
        for metric in sorted(duration_metrics, key=lambda m: m.name):
            parsed_val = None
            while parsed_val is None:
                value = input("  {} ({} remaining): ".format(metric.name, remainder))
                if value.lower() == "rest":
                    parsed_val = remainder
                else:
                    try:
                        parsed_val = Duration.parse(value)
                    except ParsingError as e:
                        self._error(str(e))
                    except:
                        self._error("Invalid duration")

                if parsed_val > remainder:
                    self._error(
                        "{} is greater than remaining time from " "stopwatch ({})".format(parsed_val, remainder)
                    )
                    parsed_val = None

            task.record(metric, parsed_val)
            remainder -= parsed_val

            if remainder.total_seconds() <= 0:
                break

        self._print()
Beispiel #2
0
def test_duration_multiple():
    value = Duration.parse("2 hrs, 5 mins")
    assert value == timedelta(hours=2, minutes=5)
Beispiel #3
0
def test_duration_days():
    value = Duration.parse("2 days")
    assert value == timedelta(days=2)
Beispiel #4
0
def test_duration_seconds():
    value = Duration.parse("4.5 seconds")
    assert value == timedelta(seconds=4, milliseconds=500)

    value = Duration.parse("525s")
    assert value == timedelta(seconds=525)
Beispiel #5
0
def test_duration_minutes():
    value = Duration.parse("4 minutes")
    assert value == timedelta(minutes=4)

    value = Duration.parse("4.5 mins")
    assert value == timedelta(minutes=4, seconds=30)
Beispiel #6
0
def test_duration_hours():
    value = Duration.parse("4 hours")
    assert value == timedelta(hours=4)

    value = Duration.parse("4.5 hours")
    assert value == timedelta(hours=4, minutes=30)
Beispiel #7
0
def test_duration_timefmt():
    value = Duration.parse("10:05:01")
    assert value == timedelta(hours=10, minutes=5, seconds=1)

    value = Duration.parse("10:05")
    assert value == timedelta(hours=10, minutes=5)