mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-03-26 19:31:19 +01:00
feat: add common function for returning remaining days in a month
This commit is contained in:
17
app/apps/common/functions/dates.py
Normal file
17
app/apps/common/functions/dates.py
Normal 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
|
||||
Reference in New Issue
Block a user