Skip to main content

Create dates from natural language expressions

Project description

stringtime

PyPI version Downloads Python version Python package

A grammar for deriving Date objects from phrases.

Usage

from stringtime import Date

d = Date('an hour from now')
d.day  # the day of the week 0-6
d.get_day(to_string=True) # the day name, e.g. 'Monday'
d.month  # the month 0-11
d.hour  # the hour 0-23
d.get_month(to_string=True) # the month name, e.g. 'January'

# also wraps dateutil.parser so can parse full date strings
d = Date("Sat Oct 11 17:13:46 UTC 2003")

Installation

python3 -m pip install stringtime
# python3 -m pip install stringtime --upgrade

Usage and API

Here's a list of example phrases that can be used...

"an hour from now"
"1 hour from now"
"1 hour ago"
"Today"
"Yesterday"
"Tomorrow"
"Tuesday"
"On Wednesday"
"In a minute"
"In an hour"
"20hrs from now"
"In a day/week/month/year"
"In 2 years"
"20mins in the future"
"20mins in the past"
"In 15 minutes"
"5 hours from now"
"20 minutes hence"
"10 minutes ago"
"24 hours ago"
"3 weeks ago"
"30 seconds ago"
"1 hour before now"
"1 hour after now"
"1 hour ago"
"This Friday at 1"
"Last Wednesday at 5"
# dates without a month specified will use the current month
"12th"
"The 8th"
"On the 14th"
"January 14th"
"April the 1st"
"32nd", # would move into the next month
"The 18th of March"

To see what else is underway check the tests/test_stringtime.py file.

If anything is broken or you feel is missing please raise an issue or make a pull request.

CLI

Use stringtime from the command line:

stringtime -p 2 days from now

Dev

Clone the repo and install dev requirements:

python3 -m ven venv
python3 -m pip install -r requirements-dev.txt

to dev see the tests and add more or uncomment some that are not passing yet.

Run tests

See the make file...

make test

License

Do what you want with this code.

Uses David Beazley's PLY parser.

Disclaimer

Might be buggy... still only recent

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stringtime-0.0.6.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

stringtime-0.0.6-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file stringtime-0.0.6.tar.gz.

File metadata

  • Download URL: stringtime-0.0.6.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.26.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for stringtime-0.0.6.tar.gz
Algorithm Hash digest
SHA256 50300275efb8d5e7365080ea3e06750ebabdbcfe4ea2e21d92b429066bc2c71e
MD5 42400fb47a0da561dc7dc75614dc63f0
BLAKE2b-256 2d5194b84b470f1515ff9ce2a5e25ac08efa3631e898a9184785d1c1ed9a481c

See more details on using hashes here.

Provenance

File details

Details for the file stringtime-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: stringtime-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.26.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for stringtime-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 3ce2dec4e0c8ed5729b14d42eda869922a6df840440b9ac7b962aabf9bd7301f
MD5 3cd21b8a2b3a83101eb11280bb9b8ea2
BLAKE2b-256 1a343e9ee87eb83878ee45c7b095cb35d23063016b3f7be077eba8b840ebd26e

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page