"""
Date Intelligence
Generated by Eden via recursive self-improvement
2025-10-28 13:44:08.384591
"""

from datetime import datetime, timedelta
from dateutil.parser import parse as dateparse

class DateIntelligence:
    """
    A class to manage and manipulate dates intelligently.
    
    Attributes:
        date_str (str): Input date string
        parsed_date (datetime): Parsed date object
    """

    def __init__(self, date_input):
        self.date_str = date_input
        try:
            self.parsed_date = self.parse_date(date_input)
        except ValueError as e:
            raise ValueError(f"Invalid date format: {e}")

    def parse_date(self, date_str):
        """
        Parses a date string into a datetime object.
        
        Args:
            date_str (str): Input date string in various formats
            
        Returns:
            datetime: Parsed date object
        """
        try:
            return dateparse(date_str)
        except ValueError:
            raise ValueError("Date string could not be parsed")

    def convert_to_iso(self):
        """
        Converts the parsed date to ISO format (YYYY-MM-DD).
        
        Returns:
            str: ISO formatted date string
        """
        return self.parsed_date.strftime("%Y-%m-%d")

    def add_days(self, days=1):
        """
        Adds a specified number of days to the date.
        
        Args:
            days (int): Number of days to add. Defaults to 1
            
        Returns:
            datetime: New date object after adding days
        """
        return self.parsed_date + timedelta(days=days)

    def subtract_days(self, days=1):
        """
        Subtracts a specified number of days from the date.
        
        Args:
            days (int): Number of days to subtract. Defaults to 1
            
        Returns:
            datetime: New date object after subtracting days
        """
        return self.parsed_date - timedelta(days=days)

    def calculate_difference(self, other_date):
        """
        Calculates the difference in days between two dates.
        
        Args:
            other_date (str or datetime): Another date to compare
            
        Returns:
            int: Difference in days
        """
        if isinstance(other_date, str):
            other_parsed = dateparse(other_date)
        else:
            other_parsed = other_date
        return (self.parsed_date - other_parsed).days

    def find_next_occurrence(self, target_weekday):
        """
        Finds the next occurrence of a specified weekday from the current date.
        
        Args:
            target_weekday (str): Name of the weekday to find (e.g., 'Monday', 'Tuesday')
            
        Returns:
            datetime: Date of the next occurrence
        """
        days_to_add = (target_weekday.weekday() - self.parsed_date.weekday()) % 7
        return self.add_days(days=days_to_add)

# Example usage:
if __name__ == "__main__":
    # Initialize with a date string
    di = DateIntelligence("2023-10-05")
    
    print("Original Date:", di.parsed_date)
    print("ISO Format:", di.convert_to_iso())
    print("Next Day:", di.add_days().date())
    print("Previous Day:", di.subtract_days().date())
    
    # Calculate difference between two dates
    other_date = DateIntelligence("2024-10-05")
    print("Days Difference:", di.calculate_difference(other_date))
    
    # Find next Monday
    next_monday = di.find_next_occurrence(datetime.strptime('Monday', '%A'))
    print("Next Monday:", next_monday.date())