Module that allows extracting valid date from user input.
Project description
Datify
This Python3 module allows extracting parts of valid date from user input.
User input is processed through class Datify
.
Languages supported:
- English
- Russian
- Ukrainian
Installing
Simply run pip install datify
from your command line (pip must be installed).
Class:
Datify(user_input, year, month, date)
: takes str when creating. Also, can take particular parameters like year
, month
, and day
along with user input or without it. If no parameters are given, raises ValueError. See the section Formats to discover default Datify's formats.
Class methods:
Static:
find_date(string)
: Takes string. Returns substring with date in General Date format if it is contained in the given string.is_year(year)
: Takes str or int. Returns True if given parameter suits year format.is_digit_month(month)
: Takes str or int. Returns True if given parameter suits digit month format.is_alpha_month(string)
: Takes str. Returns True if given string suits months dictionary. For languages in which there are multiple forms of words it's basically enough to have only the main form of the word in dictionary.get_alpha_month(string)
: Takes str. Returns number(int) of month name in given string according to months dictionary. If no month name is found in the string, returns None.is_day(day)
: Takes str or int. Returns True if given parameter suits day format.is_date(date)
: Takes str or int. Returns True if given parameter suits general date format (See the section Formats).is_date_dart(string)
: Takes str. Returns True if given string contains at least one of date parts such as day, month, or year.
Instance:
date()
: returns datetime object from parameters of Datify object. If not all of the necessary parameters are known (year
,month
, andday
), raises TypeError.tuple()
: returns tuple from all parameters in format (day, month, year).date_or_tuple()
: returns datetime object if all of the necessary parameters are known, otherwise returns tuple of all parameters.set_year(year)
: Takes str or int. Extracts year from given parameter and setsyear
field of the called Datify object. If given parameter doesn't suit year format, raises ValueError. If the year is given in shortened format, counts it as 20YY.set_month(month)
: Takes str or int. Extracts month from given parameter and setsmonth
field of the called Datify object. If given parameter doesn't suit month format and doesn't contain any month names, raises ValueError.set_day(day)
: Takes str or int. Extracts day from given parameter and setsday
field of the called Datify object. If given parameter doesn't suit day format, raises ValueError.
More information on GitHub: https://github.com/mitryp/datify
Datify is much more powerful than you may think.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.