Hacker News new | ask | show | jobs
by gabrielsroka 1055 days ago
I would have changed the following two lines, that way, you don't have to know what the last day of the month is.

   end_date = datetime(2023, 7, 1)
   # ...
   while current_date < end_date:
This is a lot shorter though maybe harder to read:

  >>> import calendar
  >>> c = calendar.Calendar()
  >>> sum(d > 0 and calendar.MONDAY <= w <= calendar.FRIDAY for d, w in c.itermonthdays2(2023, 6))
  22
https://docs.python.org/3/library/calendar.html#calendar.Cal...