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"

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

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.3.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

stringtime-0.0.3-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stringtime-0.0.3.tar.gz
  • Upload date:
  • Size: 15.7 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.3.tar.gz
Algorithm Hash digest
SHA256 2185d6c38161e860465ab31e3ff2471b48b50918973508fb56073a865150ca3e
MD5 33b1ae1fbf0fa52f207197eccee4a849
BLAKE2b-256 e27e413cdfa8395cbb3178af540ac732c9370614a7563d8173234759fc4f1560

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stringtime-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 15.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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 07fc800d05b55bb1e100756622423751d3e80bc050fde0fc3bb43c1e660f3b95
MD5 891043187f9f970570ef8d99b0337042
BLAKE2b-256 bb6b86e92cf0d547508e4915a2d1700c119b69cfdef5909582acbef5bafc0565

See more details on using hashes here.

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