datetime.py 1023 B

12345678910111213141516171819202122232425
  1. from datetime import datetime
  2. from flask import render_template
  3. def filter_accounts_current_month(accounts):
  4. # Get the start and end of the current month
  5. now = datetime.now()
  6. start_of_month = datetime(now.year, now.month, 1)
  7. if now.month == 12:
  8. # If current month is December, next month is January of the next year
  9. start_of_next_month = datetime(now.year + 1, 1, 1)
  10. else:
  11. # Otherwise, next month is just the next month of the same year
  12. start_of_next_month = datetime(now.year, now.month + 1, 1)
  13. # Convert start and end of the month to epoch timestamps
  14. start_of_month_timestamp = int(start_of_month.timestamp())
  15. start_of_next_month_timestamp = int(start_of_next_month.timestamp())
  16. # Filter accounts with expiryDate in the current month
  17. accounts_in_current_month = [
  18. account for account in accounts
  19. if start_of_month_timestamp <= account['expiaryDate'] < start_of_next_month_timestamp
  20. ]
  21. return accounts_in_current_month