Skip to content

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

@SimoneMoreWare

Description

@SimoneMoreWare

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions