feat: add common function for returning remaining days in a month

This commit is contained in:
Herculino Trotta
2024-09-26 21:29:55 -03:00
parent 9e8c81a0d9
commit f0ead20b57

View File

@@ -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