intent.dates

Used to extract dates and times described as text.

class intent.dates.DateService(tz=None, now=None)

Initialize a DateService for extracting dates from text.

Args:
tz: An optional Pytz timezone. All datetime objects returned will
be relative to the supplied timezone, or timezone-less if none is supplied.
now: The time to which all returned datetime objects should be
relative. For example, if the text is “In 5 hours”, the datetime returned will be now + datetime.timedelta(hours=5). Uses datetime.datetime.now() if none is supplied.
Returns:
A DateService which uses tz and now for all of its computations.
convertDate(date, prefix='', weekday=False)

Convert a datetime object representing into a human-ready string that can be read, spoken aloud, etc. In effect, runs both convertDay and convertTime on the input, merging the results.

Args:

date (datetime.date): A datetime object to be converted into text. prefix (str): An optional argument that prefixes the converted

string. For example, if prefix=”in”, you’d receive “in two days”, rather than “two days”, while the method would still return “tomorrow” (rather than “in tomorrow”).
weekday (bool): An optional argument that returns “Monday, Oct. 1”
if True, rather than “Oct. 1”.
Returns:
A string representation of the input day and time.
convertDay(day, prefix='', weekday=False)

Convert a datetime object representing a day into a human-ready string that can be read, spoken aloud, etc.

Args:

day (datetime.date): A datetime object to be converted into text. prefix (str): An optional argument that prefixes the converted

string. For example, if prefix=”in”, you’d receive “in two days”, rather than “two days”, while the method would still return “tomorrow” (rather than “in tomorrow”).
weekday (bool): An optional argument that returns “Monday, Oct. 1”
if True, rather than “Oct. 1”.
Returns:
A string representation of the input day, ignoring any time-related information.
convertTime(time)

Convert a datetime object representing a time into a human-ready string that can be read, spoken aloud, etc.

Args:
time (datetime.date): A datetime object to be converted into text.
Returns:
A string representation of the input time, ignoring any day-related information.
parseDate(input)

Extract semantic date information from an input string. In effect, runs both parseDay and parseTime on the input string and merges the results to produce a comprehensive datetime object.

Args:
input (str): Input string to be parsed.
Returns:
A datetime object containing the extracted date from the input snippet, or None if not found.
parseDay(input)

Extracts day-related information from an input string. Ignores any information related to the specific time-of-day.

parseTime(input)

Extracts time-related information from an input string. Ignores any information related to the specific date, focusing on the time-of-day.

intent.dates.extractDate(input, tz=None, now=None)

Extract semantic date information from an input string. This is a convenience method which would only be used if you’d rather not initialize a DateService object.

Args:

input (str): The input string to be parsed. tz: An optional Pytz timezone. All datetime objects returned will

be relative to the supplied timezone, or timezone-less if none is supplied.
now: The time to which all returned datetime objects should be
relative. For example, if the text is “In 5 hours”, the datetime returned will be now + datetime.timedelta(hours=5). Uses datetime.datetime.now() if none is supplied.
Returns:
A datetime objected extracted from input, or None if not found.

Previous topic

Documentation

Next topic

intent.numbers

This Page