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

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

Uploaded Source

Built Distribution

stringtime-0.0.4-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stringtime-0.0.4.tar.gz
  • Upload date:
  • Size: 18.5 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.4.tar.gz
Algorithm Hash digest
SHA256 dafecd0245136fd2f9d5df890584451a1c1c4ec6e0fd93f8a5463f68f75f5550
MD5 2132b9d7f6ad88a36311fac0044fc26a
BLAKE2b-256 61790dfdefdc596d04b1c6a50bd03de0a73c612a51c105d022f56e0d995ec2e6

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: stringtime-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 17.9 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 787dbadb40fe9e970cc2dc2cb698e1fb9635555cce47f4278ec3e74eb0ffca1d
MD5 feaf1a4e6424bd46d375e3fea94936c2
BLAKE2b-256 07df69c080f0b33a3e335bdd8f9df41bf5eceae3fa0f60f893fd559978961932

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