KTVManager_UI/lib/datetime.py
2024-11-02 20:04:56 +00:00

26 lines
1023 B
Python

from datetime import datetime
from flask import render_template
def filter_accounts_current_month(accounts):
# Get the start and end of the current month
now = datetime.now()
start_of_month = datetime(now.year, now.month, 1)
if now.month == 12:
# If current month is December, next month is January of the next year
start_of_next_month = datetime(now.year + 1, 1, 1)
else:
# Otherwise, next month is just the next month of the same year
start_of_next_month = datetime(now.year, now.month + 1, 1)
# Convert start and end of the month to epoch timestamps
start_of_month_timestamp = int(start_of_month.timestamp())
start_of_next_month_timestamp = int(start_of_next_month.timestamp())
# Filter accounts with expiryDate in the current month
accounts_in_current_month = [
account for account in accounts
if start_of_month_timestamp <= account['expiaryDate'] < start_of_next_month_timestamp
]
return accounts_in_current_month