KTVManager_UI/lib/datetime.py

47 lines
1.7 KiB
Python
Raw Permalink Normal View History

2025-03-03 08:37:45 +00:00
from datetime import datetime, timedelta
2024-11-07 20:04:54 +00:00
from typing import List, Dict
2024-11-02 20:04:56 +00:00
2025-03-03 08:37:45 +00:00
def filter_accounts_next_30_days(accounts: List[Dict[str, int]]) -> List[Dict[str, int]]:
"""Filter accounts whose expiry date falls within the next 30 days.
2024-11-07 20:04:54 +00:00
Args:
accounts (List[Dict[str, int]]): A list of account dictionaries, each containing
an 'expiaryDate' key with an epoch timestamp as its value.
Returns:
2025-03-03 08:37:45 +00:00
List[Dict[str, int]]: A list of accounts expiring within the next 30 days.
2024-11-07 20:04:54 +00:00
"""
2024-11-02 20:04:56 +00:00
now = datetime.now()
2025-03-03 08:37:45 +00:00
thirty_days_later = now + timedelta(days=30)
# Convert current time and 30 days later to epoch timestamps
now_timestamp = int(now.timestamp())
thirty_days_later_timestamp = int(thirty_days_later.timestamp())
# Filter accounts with expiryDate within the next 30 days
return [
2024-11-02 20:04:56 +00:00
account for account in accounts
2025-03-03 08:37:45 +00:00
if now_timestamp <= account['expiaryDate'] < thirty_days_later_timestamp
2024-11-02 20:04:56 +00:00
]
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