Пример #1
0
def test_records_begin_end(mocker, timer_service, reporting_service):
    t0 = datetime.now(tz_local()).replace(microsecond=0) - timedelta(hours=4)
    t1 = t0 + timedelta(hours=3)

    tt.cli.main(["records", "--begin", t0.isoformat(), "--end", t1.isoformat()])

    reporting_service.timers_by_day.assert_called_once_with(start=t0, end=t1)
Пример #2
0
def test_summary_begin_end(timer_service, reporting_service):
    t0 = datetime.now(tz_local()).replace(microsecond=0) - timedelta(hours=4)
    t1 = t0 + timedelta(hours=3)

    tt.cli.main(["summary", "--begin", t0.isoformat(), "--end", t1.isoformat()])

    reporting_service.summary_by_task.assert_called_once_with(start=t0, end=t1)
Пример #3
0
def test_records(mock_datetime, timer_service, reporting_service):
    t0 = start_of_day(datetime.now(tz_local()))
    t1 = t0 + timedelta(days=1)

    mock_datetime.now.return_value = t0
    tt.cli.main(["records"])

    reporting_service.timers_by_day.assert_called_once_with(start=t0, end=t1)
Пример #4
0
def test_from_timetrange_last_year(mock_datetime, mocker):
    t = datetime(2018, 2, 23, 15, 16, 00, tzinfo=tz_local())

    mock_datetime.now.return_value = t

    args = mocker.MagicMock()
    args.yesterday = False
    args.week = False
    args.last_week = False
    args.month = False
    args.last_month = False
    args.year = False
    args.last_year = True

    assert tt.cli.from_timerange(args) == (
        datetime(2017, 1, 1, 0, 0, tzinfo=tz_local()),
        datetime(2018, 1, 1, 0, 0, tzinfo=tz_local()),
    )
Пример #5
0
def test_summary(mock_datetime, timer_service, reporting_service):
    t0 = start_of_day(datetime.now(tz_local()))
    t1 = t0 + timedelta(days=1)

    mock_datetime.now.return_value = t0

    tt.cli.main(["summary"])

    reporting_service.summary_by_task.assert_called_once_with(start=t0, end=t1)
Пример #6
0
def slices():
    return [
        {
            "start": datetime(2018, 2, 28, 9, 0, tzinfo=tz_local()),
            "elapsed": timedelta(hours=1),
            "task": "one",
        },
        {
            "start": datetime(2018, 2, 28, 10, 0, tzinfo=tz_local()),
            "elapsed": timedelta(hours=2),
            "task": "two",
        },
        {
            "start": datetime(2018, 2, 28, 11, 0, tzinfo=tz_local()),
            "elapsed": timedelta(hours=4),
            "task": "one",
        },
        {
            "start": datetime(2018, 3, 1, 9, 0, tzinfo=tz_local()),
            "elapsed": timedelta(hours=8),
            "task": "two",
        },
        {
            "start": datetime(2018, 3, 1, 10, 0, tzinfo=tz_local()),
            "elapsed": timedelta(hours=16),
            "task": "one",
        },
        {
            "start": datetime(2018, 3, 1, 11, 0, tzinfo=tz_local()),
            "elapsed": timedelta(hours=32),
            "task": "two",
        },
    ]
Пример #7
0
def from_timerange(args):
    """Return datetimes for timetranges specified in the arguments.

    Allowed timeranges are:
      * yesterday
      * week
      * last_week
      * month
      * last_month
      * year
      * last_year

    :param args: parsed command line arguments.
    :returns: A tuple of timezone aware datetime objects representing
              the start (inclusive) and end (exclusive) for the given
              timerange, or the start and end of the current day if not
              specified.
    """
    now = datetime.now(tz_local())

    if args.yesterday:
        return start_of_day(now - timedelta(days=1)), start_of_day(now)

    if args.week:
        return start_of_week(now), start_of_week(now + timedelta(days=7))

    if args.last_week:
        return start_of_week(now - timedelta(days=7)), start_of_week(now)

    if args.month:
        return (
            start_of_month(now.replace(day=15)),
            start_of_month(now.replace(day=15) + timedelta(days=30)),
        )

    if args.last_month:
        return (
            start_of_month(now.replace(day=15) - timedelta(days=30)),
            start_of_month(now.replace(day=15)),
        )

    if args.year:
        return start_of_year(now), start_of_year(now + timedelta(days=365))

    if args.last_year:
        return start_of_year(now - timedelta(days=365)), start_of_year(now)

    return start_of_day(now), start_of_day(now + timedelta(days=1))
Пример #8
0
def test_report_with_month(month, timer_service, reporting_service):
    options = ["report", "--month", str(month)]

    tt.cli.main(options)

    today = datetime.now(tz_local()).replace(hour=0, minute=0, second=0, microsecond=0)
    if month > today.month:
        today = today.replace(year=today.year - 1)
    last_day_of_month = calendar.monthrange(today.year, month)[1]

    start = today.replace(day=1, month=month)
    end = today.replace(day=last_day_of_month, month=month)

    reporting_service.summary_by_day_and_task.assert_called_once_with(
        start=start, end=end
    )
Пример #9
0
def do_report(args):
    timer_service = TimerService()
    reporting_service = ReportingService(timer_service)

    target_date = datetime.now(tz_local()).replace(hour=0,
                                                   minute=0,
                                                   second=0,
                                                   microsecond=0)

    if args.month:
        if args.month > target_date.month:
            target_date = target_date.replace(year=target_date.year - 1)
        target_date = target_date.replace(month=args.month)

    last_day_of_month = calendar.monthrange(target_date.year,
                                            target_date.month)[1]

    start = target_date.replace(day=1)
    end = target_date.replace(day=last_day_of_month)
    for weekly_report in reporting_service.summary_by_day_and_task(start=start,
                                                                   end=end):
        print("%s\n" % weekly_report)
Пример #10
0
def do_status(args):
    timer_service = TimerService()
    reporting_service = ReportingService(timer_service)

    now = datetime.now(tz_local()).replace(hour=0,
                                           minute=0,
                                           second=0,
                                           microsecond=0)

    week_begin, week_end = tt.datetime.week_boundaries(now)

    day_begin = now
    day_end = now + timedelta(days=1)
    try:
        print(
            next(
                reporting_service.summary_by_day_and_task(start=week_begin,
                                                          end=week_end)))
        print("\n")
        print(
            next(reporting_service.timers_by_day(start=day_begin,
                                                 end=day_end)))
    except StopIteration:
        print("No records")