at-date
Simple Python library for parsing at command string into datetime objects.
Content
Installation
At-date requires Python 3.4 or higher.
You can install package using pip:
pip install atdate
Or with pipenv:
pipenv install atdate
If you want to use latest unreleased version use the code from master branch:
git clone git@github.com:destag/at-date.git
cd at-date/
python setup.py install
Guide
Basic Usage
To start using at-date import parse function and provide valid at date string.
>>> from atdate import parse
>>> parse('noon next day')
datetime.datetime(2018, 10, 11, 12, 0)
>>> parse('now + 8 hours')
datetime.datetime(2018, 10, 10, 15, 42, 24)
Or you can use AtDateParser object.
>>> from atdate import AtDateParser
>>> parser = AtDateParser()
>>> parser.execute('now + 8 hours')
datetime.datetime(2018, 10, 10, 15, 42, 24)
Function parse
Parses string in at date format to valid datetime object.
Arguments:
- at_date_string (str): Valid at date string.
Returns:
- datetime.datetime: Date and time to which string has been parsed.
At date string
Valid at date string consists of tokens which can be in order:
| tokens | example |
|---|---|
| time | 17:32 |
| time | 17:32 11/22/2033 |
| time | 17:32 next day |
| time increment | 17:32 11/22/2033 next day |
| date | 11/22/2033 |
| date | 11/22/2033 17:32 |
| date | 11/22/2033 next month |
| now | now |
| now | now next day |
| increment | next month |
| isodatetime | 2033-11-22T17:32 |
At date tokens
These are valid formats for at date string tokens.
time
Format for describing time.
| format | example |
|---|---|
| [00-23] [00-59] | 1732 |
| [0-23] : [0-59] | 17:32 |
| [00-12] [00-59] [am|pm] | 0532 pm |
| [0-12] : [0-59] [am|pm] | 5:32 pm |
| [noon|midnight] | noon |
date
Format for describing date.
| format | example |
|---|---|
| [month][1-31] | october 27 |
| [1-12] / [1-31] | 10/27 |
| [1-12] / [1-31] / [0-9999] | 10/27/2006 |
| [1-12] . [1-31] | 10.27 |
| [1-12] . [1-31] . [0-9999] | 10.27.2006 |
| [0-9999] - [1-12] - [1-31] | 2006-10-27 |
increment
Format for describing time incrementation.
| format | example |
|---|---|
| next [period] | next month |
| + [0-9999] [period] | + 12 minutes |
isodatetime
Format for ISO 8601 date time.
| format | example |
|---|---|
| [0-9999] - [1-12] - [1-31] T [0-23] : [0-59] | 2033-11-22T17:32 |
now
Format for this token is literally now.
Returns actual date and time.
month
Month name is case insensitive. You can use whole name or shortcut. All months with shortcuts are listed in table.
| name | shortcut |
|---|---|
| january | jan |
| february | feb |
| march | mar |
| april | apr |
| may | may |
| june | jun |
| july | jul |
| august | aug |
| september | sep |
| october | oct |
| november | nov |
| december | dec |
weekday
Weekday name is case insensitive. You can use whole name or shortcut. All weekdays with shortcuts are listed in table.
| name | shortcut |
|---|---|
| monday | mon |
| tuesday | tue |
| wednesday | wed |
| thursday | thu |
| friday | fri |
| saturday | sat |
| sunday | sun |
period
Format for describing period of time. Can end with s. All possible formats are listed in table.
| name | s |
|---|---|
| minute | minutes |
| hour | hours |
| day | days |
| week | weeks |
| month | months |
| year | years |
Final notes
Thank you for using at-date. If you found any bugs, have a question or want a feature to be added feel free to open issue on GitHub.