Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Matching "now" for Current Date and Time #28

Open
SimoneMoreWare opened this issue Aug 23, 2024 · 0 comments
Open

Issue with Matching "now" for Current Date and Time #28

SimoneMoreWare opened this issue Aug 23, 2024 · 0 comments

Comments

@SimoneMoreWare
Copy link

SimoneMoreWare commented Aug 23, 2024

Thank you for creating and maintaining the recurrent library—it's a powerful tool for parsing natural language date and time expressions. However, I've noticed an issue where the library doesn't correctly interpret the word "now" as the current date and time.

Here the code with an example

import datetime
from recurrent.event_parser import RecurringEvent

# Create an instance of the parser with the current date and time
now_date = datetime.datetime.now()
parser = RecurringEvent(now_date=now_date)

# Define the specific string to test
time_string = "are you free now?"

# Function to extract dates
def extract_dates(text):
    """
    Parses the provided text to extract a date or time.
    
    Args:
        text (str): The natural language text to parse.
        
    Returns:
        datetime.datetime or None: The parsed datetime object or None if parsing fails.
    """
    try:
        parsed_date = parser.parse(text)  # Parse the input text
        if isinstance(parsed_date, datetime.datetime):  # Check if the result is a datetime object
            return parsed_date  # Return the parsed date
        else:
            return None  # Return None if parsing fails or the result is not a datetime
    except Exception as e:
        return str(e)  # Return the exception message if an error occurs

# Extract the date for the specific test string
extracted_date = extract_dates(time_string)

# Print the result
print(f"'{time_string}':\t{extracted_date}")

This is the ouput:

issueTime

Expected Behavior:
The library should return the current date and time when parsing the word "now".

Actual Behavior:
The library fails to return the current date and time or does not recognize "now" correctly.

Improving the handling of the word "now" would enhance the library’s ability to process real-time queries. Thank you for considering this enhancement!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant