Skip to content

Commit

Permalink
Issue 796: remove days of the week from human readable description wh…
Browse files Browse the repository at this point in the history
…en the whole week is specified
  • Loading branch information
Valentina Khudiakova authored and auvipy committed Aug 28, 2024
1 parent b31fde0 commit b2a7f56
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 4 additions & 1 deletion django_celery_beat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,10 @@ def human_readable(self):
day_of_month=self.day_of_month,
month_of_year=self.month_of_year,
)
day_of_week = cronexp(",".join(str(day) for day in c.day_of_week))
if c.day_of_week and set(c.day_of_week) == set(range(7)):
day_of_week = "*"
else:
day_of_week = cronexp(",".join(map(str, c.day_of_week)))
except ValueError:
day_of_week = cronexp(self.day_of_week)

Expand Down
19 changes: 13 additions & 6 deletions t/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,16 @@ def test_invalid(self):
def test_long_name(self):
"""Long day name display."""
for day_day_of_week, expected in (
("1", "Monday"),
("mon", "Monday"),
("Monday,tue", "Monday and Tuesday"),
("sat-sun/2", "Saturday"),
("mon-wed", "Monday, Tuesday, and Wednesday"),
("1", ", only on Monday"),
("mon", ", only on Monday"),
("Monday,tue", ", only on Monday and Tuesday"),
("sat-sun/2", ", only on Saturday"),
("mon-wed", ", only on Monday, Tuesday, and Wednesday"),
("*", ""),
("0-6", ""),
("2-1", ""),
("mon-sun", ""),
("tue-mon", ""),
):
cron = CrontabSchedule.objects.create(
hour="2",
Expand All @@ -247,5 +252,7 @@ def test_long_name(self):
)

self.assertEqual(
cron.human_readable, f"At 02:00 AM, only on {expected} UTC"
cron.human_readable,
f"At 02:00 AM{expected} UTC",
day_day_of_week,
)

0 comments on commit b2a7f56

Please sign in to comment.