2024-11-02 20:04:56 +00:00
|
|
|
from datetime import datetime
|
2024-11-07 20:04:54 +00:00
|
|
|
from typing import List, Dict
|
2024-11-02 20:04:56 +00:00
|
|
|
|
2024-11-07 20:04:54 +00:00
|
|
|
def filter_accounts_current_month(accounts: List[Dict[str, int]]) -> List[Dict[str, int]]:
|
|
|
|
"""Filter accounts whose expiry date falls within the current month.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
accounts (List[Dict[str, int]]): A list of account dictionaries, each containing
|
|
|
|
an 'expiaryDate' key with an epoch timestamp as its value.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
List[Dict[str, int]]: A list of accounts expiring in the current month.
|
|
|
|
"""
|
|
|
|
# Get the start of the current month
|
2024-11-02 20:04:56 +00:00
|
|
|
now = datetime.now()
|
|
|
|
start_of_month = datetime(now.year, now.month, 1)
|
2024-11-07 20:04:54 +00:00
|
|
|
|
|
|
|
# Determine the start of the next month
|
2024-11-02 20:04:56 +00:00
|
|
|
if now.month == 12:
|
2024-11-07 20:04:54 +00:00
|
|
|
# If the current month is December, next month is January of the next year
|
2024-11-02 20:04:56 +00:00
|
|
|
start_of_next_month = datetime(now.year + 1, 1, 1)
|
|
|
|
else:
|
2024-11-07 20:04:54 +00:00
|
|
|
# Otherwise, the next month is the following month of the same year
|
2024-11-02 20:04:56 +00:00
|
|
|
start_of_next_month = datetime(now.year, now.month + 1, 1)
|
2024-11-07 20:04:54 +00:00
|
|
|
|
2024-11-02 20:04:56 +00:00
|
|
|
# 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
|
2024-11-07 20:04:54 +00:00
|
|
|
|
|
|
|
def filter_accounts_expired(accounts: List[Dict[str, int]]) -> List[Dict[str, int]]:
|
|
|
|
"""Filter accounts whose expiry date has passed.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
accounts (List[Dict[str, int]]): A list of account dictionaries, each containing
|
|
|
|
an 'expiaryDate' key with an epoch timestamp as its value.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
List[Dict[str, int]]: A list of accounts that have expired.
|
|
|
|
"""
|
|
|
|
# Get the current epoch timestamp
|
|
|
|
current_timestamp = int(datetime.now().timestamp())
|
|
|
|
|
|
|
|
# Filter accounts where the current date is greater than the expiryDate
|
|
|
|
expired_accounts = [
|
|
|
|
account for account in accounts
|
|
|
|
if account['expiaryDate'] < current_timestamp
|
|
|
|
]
|
|
|
|
|
|
|
|
return expired_accounts
|