The pdt_locales Module

pdt_locales

All of the included locale classes shipped with pdt.

cloudfusion.third_party.parsedatetime.parsedatetime.pdt_locales.lcase(x)
class cloudfusion.third_party.parsedatetime.parsedatetime.pdt_locales.pdtLocale_au

Bases: cloudfusion.third_party.parsedatetime.parsedatetime.pdt_locales.pdtLocale_base

en_AU Locale

class cloudfusion.third_party.parsedatetime.parsedatetime.pdt_locales.pdtLocale_base

Bases: object

default values for Locales

locale_keys = ['MonthOffsets', 'Months', 'WeekdayOffsets', 'Weekdays', 'dateFormats', 'dateSep', 'dayOffsets', 'dp_order', 'localeID', 'meridian', 'Modifiers', 're_sources', 're_values', 'shortMonths', 'shortWeekdays', 'timeFormats', 'timeSep', 'units', 'uses24', 'usesMeridian', 'numbers']
class cloudfusion.third_party.parsedatetime.parsedatetime.pdt_locales.pdtLocale_de

Bases: cloudfusion.third_party.parsedatetime.parsedatetime.pdt_locales.pdtLocale_base

de_DE Locale constants

Contributed by Debian parsedatetime package maintainer Bernd Zeimetz <bzed@debian.org>

class cloudfusion.third_party.parsedatetime.parsedatetime.pdt_locales.pdtLocale_en

Bases: cloudfusion.third_party.parsedatetime.parsedatetime.pdt_locales.pdtLocale_base

en_US Locale

class cloudfusion.third_party.parsedatetime.parsedatetime.pdt_locales.pdtLocale_es

Bases: cloudfusion.third_party.parsedatetime.parsedatetime.pdt_locales.pdtLocale_base

es Locale

Note that I don’t speak Spanish so many of the items below are still in English

class cloudfusion.third_party.parsedatetime.parsedatetime.pdt_locales.pdtLocale_icu(localeID)

Bases: cloudfusion.third_party.parsedatetime.parsedatetime.pdt_locales.pdtLocale_base

Create a locale from pyICU

The parsedatetime Package

parsedatetime

Parse human-readable date/time text.

Requires Python 2.6 or later

class cloudfusion.third_party.parsedatetime.parsedatetime.Calendar(constants=None)

A collection of routines to input, parse and manipulate date and times. The text can either be ‘normal’ date values or it can be human readable.

Default constructor for the L{Calendar} class.

@type constants: object @param constants: Instance of the class L{Constants}

@rtype: object @return: L{Calendar} instance

_CalculateDOWDelta(wd, wkdy, offset, style, currentDayStyle)

Based on the C{style} and C{currentDayStyle} determine what day-of-week value is to be returned.

@type wd: integer @param wd: day-of-week value for the current day @type wkdy: integer @param wkdy: day-of-week value for the parsed day @type offset: integer @param offset: offset direction for any modifiers (-1, 0, 1) @type style: integer @param style: normally the value set in C{Constants.DOWParseStyle} @type currentDayStyle: integer @param currentDayStyle: normally the value set in C{Constants.CurrentDOWParseStyle}

@rtype: integer @return: calculated day-of-week

_UnitsTrapped(s, m, key)
_buildTime(source, quantity, modifier, units)

Take C{quantity}, C{modifier} and C{unit} strings and convert them into values. After converting, calcuate the time and return the adjusted sourceTime.

@type source: time @param source: time to use as the base (or source) @type quantity: string @param quantity: quantity string @type modifier: string @param modifier: how quantity and units modify the source time @type units: string @param units: unit of the quantity (i.e. hours, days, months, etc)

@rtype: struct_time @return: C{struct_time} of the calculated time

_convertUnitAsWords(unitText)

Converts text units into their number value

Five = 5 Twenty Five = 25 Two hundred twenty five = 225 Two thousand and twenty five = 2025 Two thousand twenty five = 2025

@type unitText: string @param unitText: number text to convert

@rtype: integer @return: numerical value of unitText

_evalModifier(modifier, chunk1, chunk2, sourceTime)

Evaluate the C{modifier} string and following text (passed in as C{chunk1} and C{chunk2}) and if they match any known modifiers calculate the delta and apply it to C{sourceTime}.

@type modifier: string @param modifier: modifier text to apply to sourceTime @type chunk1: string @param chunk1: first text chunk that followed modifier (if any) @type chunk2: string @param chunk2: second text chunk that followed modifier (if any) @type sourceTime: struct_time @param sourceTime: C{struct_time} value to use as the base

@rtype: tuple @return: tuple of: remaining text and the modified sourceTime

_evalModifier2(modifier, chunk1, chunk2, sourceTime)

Evaluate the C{modifier} string and following text (passed in as C{chunk1} and C{chunk2}) and if they match any known modifiers calculate the delta and apply it to C{sourceTime}.

@type modifier: string @param modifier: modifier text to apply to C{sourceTime} @type chunk1: string @param chunk1: first text chunk that followed modifier (if any) @type chunk2: string @param chunk2: second text chunk that followed modifier (if any) @type sourceTime: struct_time @param sourceTime: C{struct_time} value to use as the base

@rtype: tuple @return: tuple of: remaining text and the modified sourceTime

_evalString(datetimeString, sourceTime=None)

Calculate the datetime based on flags set by the L{parse()} routine

Examples handled::
RFC822, W3CDTF formatted dates HH:MM[:SS][ am/pm] MM/DD/YYYY DD MMMM YYYY

@type datetimeString: string @param datetimeString: text to try and parse as more “traditional”

date/time text

@type sourceTime: struct_time @param sourceTime: C{struct_time} value to use as the base

@rtype: datetime @return: calculated C{struct_time} value or current C{struct_time}

if not parsed
_quantityToInt(quantity)

Convert a quantity, either spelled-out or numeric, to an integer

@type quantity: string @param quantity: quantity to parse to int @rtype: int @return: the quantity as an integer, defaulting to 0

evalRanges(datetimeString, sourceTime=None)

Evaluate the C{datetimeString} text and determine if it represents a date or time range.

@type datetimeString: string @param datetimeString: datetime text to evaluate @type sourceTime: struct_time @param sourceTime: C{struct_time} value to use as the base

@rtype: tuple @return: tuple of: start datetime, end datetime and the invalid flag

inc(source, month=None, year=None)

Takes the given C{source} date, or current date if none is passed, and increments it according to the values passed in by month and/or year.

This routine is needed because Python’s C{timedelta()} function does not allow for month or year increments.

@type source: struct_time @param source: C{struct_time} value to increment @type month: integer @param month: optional number of months to increment @type year: integer @param year: optional number of years to increment

@rtype: datetime @return: C{source} incremented by the number of months and/or years

nlp(inputString, sourceTime=None)

Utilizes parse() after making judgements about what datetime information belongs together.

It makes logical groupings based on proximity and returns a parsed datetime for each matched grouping of datetime text, along with location info within the given inputString.

@type inputString: string @param inputString: natural language text to evaluate @type sourceTime: struct_time @param sourceTime: C{struct_time} value to use as the base

@rtype: tuple or None @return: tuple of tuples in the format (parsed_datetime as datetime.datetime, flags as int, start_pos as int,

end_pos as int, matched_text as string) or None if there were no matches
parse(datetimeString, sourceTime=None)

Splits the given C{datetimeString} into tokens, finds the regex patterns that match and then calculates a C{struct_time} value from the chunks.

If C{sourceTime} is given then the C{struct_time} value will be calculated from that value, otherwise from the current date/time.

If the C{datetimeString} is parsed and date/time value found then the second item of the returned tuple will be a flag to let you know what kind of C{struct_time} value is being returned:

0 = not parsed at all
1 = parsed as a C{date}
2 = parsed as a C{time}
3 = parsed as a C{datetime}

@type datetimeString: string @param datetimeString: date/time text to evaluate @type sourceTime: struct_time @param sourceTime: C{struct_time} value to use as the base

@rtype: tuple @return: tuple of: modified C{sourceTime} and the result flag

parseDate(dateString, sourceTime=None)

Parse short-form date strings:

'05/28/2006' or '04.21'

@type dateString: string @param dateString: text to convert to a C{datetime}

@rtype: struct_time @return: calculated C{struct_time} value of dateString

parseDateText(dateString, sourceTime=None)

Parse long-form date strings:

'May 31st, 2006'
'Jan 1st'
'July 2006'

@type dateString: string @param dateString: text to convert to a datetime

@rtype: struct_time @return: calculated C{struct_time} value of dateString

class cloudfusion.third_party.parsedatetime.parsedatetime.Constants(localeID=None, usePyICU=True, fallbackLocales=['en_US'])

Bases: object

Default set of constants for parsedatetime.

If PyICU is present, then the class will first try to get PyICU to return a locale specified by C{localeID}. If either C{localeID} is None or if the locale does not exist within PyICU, then each of the locales defined in C{fallbackLocales} is tried in order.

If PyICU is not present or none of the specified locales can be used, then the class will initialize itself to the en_US locale.

if PyICU is not present or not requested, only the locales defined by C{pdtLocales} will be searched.

buildSources(sourceTime=None)

Return a dictionary of date/time tuples based on the keys found in self.re_sources.

The current time is used as the default and any specified item found in self.re_sources is inserted into the value and the generated dictionary is returned.

daysInMonth(month, year)

Take the given month (1-12) and a given year (4 digit) return the number of days in the month adjusting for leap year as needed

cloudfusion.third_party.parsedatetime.parsedatetime._extract_date(m)
cloudfusion.third_party.parsedatetime.parsedatetime._extract_time(m)
cloudfusion.third_party.parsedatetime.parsedatetime._initSymbols(ptc)

Initialize symbols and single character constants.

cloudfusion.third_party.parsedatetime.parsedatetime._parse_date_rfc822(dateString)

Parse an RFC822, RFC1123, RFC2822, or asctime-style date

cloudfusion.third_party.parsedatetime.parsedatetime._parse_date_w3dtf(dateString)

Table Of Contents

Previous topic

Subpackages

Next topic

The exponential_retry Module

This Page