Skip to content

Commit

Permalink
Merge pull request #1694 from emfcamp/my-day-is-frabbed
Browse files Browse the repository at this point in the history
frab output: events with a duration of >1d should render as D:HH:MM
  • Loading branch information
lukegb authored May 29, 2024
2 parents e77e421 + 956086a commit c5edbfa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion apps/schedule/schedule_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def get_duration(start_time, end_time):
duration = (end_time - start_time).total_seconds() / 60
hours = int(duration // 60)
minutes = int(duration % 60)
return "{0:01d}:{1:02d}".format(hours, minutes)
if hours < 24:
return f"{hours:d}:{minutes:02d}"
days = int(hours // 24)
hours = int(hours % 24)
return f"{days:d}:{hours:02d}:{minutes:02d}"


def get_day_start_end(dt, start_time=time(4, 0)):
Expand Down
20 changes: 20 additions & 0 deletions tests/test_schedule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from datetime import datetime

import pytest

from apps.schedule import schedule_xml


@pytest.mark.parametrize('start_time, end_time, expected', [
('2024-01-01 00:00:00', '2024-01-01 00:01:00', '0:01'),
('2024-01-01 00:00:00', '2024-01-01 00:01:45', '0:01'),
('2024-01-01 00:00:00', '2024-01-01 01:00:00', '1:00'),
('2024-01-01 00:00:00', '2024-01-01 12:00:00', '12:00'),
('2024-01-01 00:00:00', '2024-01-02 00:00:00', '1:00:00'),
('2024-01-01 00:00:00', '2024-01-02 12:34:00', '1:12:34'),
])
def test_get_duration(start_time, end_time, expected):
fmt = '%Y-%m-%d %H:%M:%S'
start_time = datetime.strptime(start_time, fmt)
end_time = datetime.strptime(end_time, fmt)
assert schedule_xml.get_duration(start_time, end_time) == expected

0 comments on commit c5edbfa

Please sign in to comment.