|
15 | 15 |
|
16 | 16 | @time_machine.travel(datetime(2025, 5, 2, 10, tzinfo=ZoneInfo("Europe/London"))) |
17 | 17 | @pytest.mark.parametrize( |
18 | | - ("dateiso", "output"), |
| 18 | + ("dateiso", "round_days", "output"), |
19 | 19 | ( |
20 | | - ("2025-05-02T09:00:00", "today"), |
21 | | - ("2025-05-01T09:00:00", "yesterday"), |
22 | | - ("2025-05-01T11:59:00", "yesterday"), |
23 | | - ("2025-04-30T08:00:00", "2 days ago"), |
24 | | - ("2025-05-03T07:00:00", "tomorrow"), |
25 | | - ("2025-05-04T12:00:00", "in 2 days"), |
26 | | - ("2024-05-02T12:00:00", "1 year ago"), |
27 | | - ("2024-04-02T12:00:00", "1 year, 1 month ago"), |
28 | | - ("2024-03-31T12:00:00", "1 year, 1 month, 2 days ago"), |
29 | | - ("2026-03-31T12:00:00", "in 10 months, 29 days"), |
| 20 | + ("2025-05-02T09:00:00", True, "today"), |
| 21 | + ("2025-05-02T09:00:00", False, "today"), |
| 22 | + ("2025-05-01T09:00:00", True, "yesterday"), |
| 23 | + ("2025-05-01T11:59:00", True, "yesterday"), |
| 24 | + ("2025-04-30T08:00:00", True, "2 days ago"), |
| 25 | + ("2025-04-30T08:00:00", False, "2 days ago"), |
| 26 | + ("2025-05-03T07:00:00", True, "tomorrow"), |
| 27 | + ("2025-05-04T12:00:00", True, "in 2 days"), |
| 28 | + ("2024-05-02T12:00:00", True, "1 year ago"), |
| 29 | + ("2024-04-02T12:00:00", True, "1 year, 1 month ago"), |
| 30 | + ("2024-03-31T12:00:00", False, "1 year, 1 month, 2 days ago"), |
| 31 | + ("2024-03-31T12:00:00", True, "1 year, 1 month ago"), |
| 32 | + ("2026-03-31T12:00:00", True, "in 11 months"), |
| 33 | + ("2026-03-31T12:00:00", False, "in 10 months, 29 days"), |
| 34 | + ("2026-04-30T12:00:00", True, "in 1 year"), |
| 35 | + ("2026-04-30T12:00:00", False, "in 11 months, 28 days"), |
| 36 | + ("2027-04-30T12:00:00", True, "in 2 years"), |
30 | 37 | ), |
31 | 38 | ) |
32 | | -def test_relative_dates(dateiso, output): |
33 | | - assert format_relative_date(datetime.fromisoformat(dateiso)) == output |
| 39 | +def test_relative_dates(dateiso, round_days, output): |
| 40 | + assert ( |
| 41 | + format_relative_date(datetime.fromisoformat(dateiso), round_days=round_days) |
| 42 | + == output |
| 43 | + ) |
34 | 44 |
|
35 | 45 |
|
36 | 46 | @time_machine.travel(datetime(2025, 5, 2, 10, tzinfo=ZoneInfo("Europe/London"))) |
|
0 commit comments