From f0ead20b57632e74e3f4d8066e00fef627b7f2dc Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Thu, 26 Sep 2024 21:29:55 -0300 Subject: [PATCH] feat: add common function for returning remaining days in a month --- app/apps/common/functions/dates.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/apps/common/functions/dates.py diff --git a/app/apps/common/functions/dates.py b/app/apps/common/functions/dates.py new file mode 100644 index 0000000..06d3b8c --- /dev/null +++ b/app/apps/common/functions/dates.py @@ -0,0 +1,17 @@ +import datetime +import calendar + + +def remaining_days_in_month(year, month, current_date: datetime.date): + # Get the number of days in the given month + _, days_in_month = calendar.monthrange(year, month) + + # Check if the given month and year match the current month and year + if current_date.year == year and current_date.month == month: + # Calculate remaining days + remaining_days = days_in_month - current_date.day + 1 + else: + # If not the current month, return the total number of days in the month + remaining_days = days_in_month + + return remaining_days