Skip to main content

A library to convert datetime to natural human readable format

Project description

pychronic

Introduction

A natural language date parser in Python. Inspired from Ruby's chronic.

Installation

pip install pychronic

Usage:

  • Datetime To Natural Langauge
 from pychronic.utils import to_natural_time
 from datetime import datetime, timedelta, date

>>> to_natural_time(datetime.now())
{'day': 'today', 'time': '10:56 PM', 'month': 'September', 'year': 2019, 'day_of_week': 'Friday'}

>>> to_natural_time(datetime.now() - timedelta(days=1))
{'day': 'yesterday', 'time': '10:56 PM', 'month': 'September', 'year': 2019, 'day_of_week': 'Thursday'}

>>> to_natural_time(datetime.now() + timedelta(days=1))            
{'day': 'tomorrow', 'time': '10:57 PM', 'month': 'September', 'year': 2019, 'day_of_week': 'Saturday'}

>>> to_natural_time(datetime(year=2019, month=1, day=1, hour=1, minute=0, second=0))
{'day': '1st', 'time': '01:00 AM', 'month': 'January', 'year': 2019, 'day_of_week': 'Tuesday'}
  • Highlight datetime in text
from pychronic.utils import highlight_from_text

>>> highlight_from_text("Tournament will commence on 12:30 PM on 23rd May and end on 25th aug")
{'input': ['Tournament', 'will', 'commence', 'on', '12:30', 'PM', 'on', '23rd', 'May', 'and', 'end', 'on', '25th', 'aug'], 'matched_pattern': [{'from_index': 4, 'to_index': 8, 'parsed_value': datetime.datetime(2019, 5, 23, 12, 30)}, {'fro
m_index': 12, 'to_index': 13, 'parsed_value': datetime.date(2019, 8, 25)}]}

>>> highlight_from_text("Tournament will commence on 11:30 PM on 23rd May and end on 25th aug")
{'input': ['Tournament', 'will', 'commence', 'on', '11:30', 'PM', 'on', '23rd', 'May', 'and', 'end', 'on', '25th', 'aug'], 'matched_pattern': [{'from_index': 4, 'to_index': 8, 'parsed_value': datetime.datetime(2019, 5, 23, 23, 30)}, {'fro
m_index': 12, 'to_index': 13, 'parsed_value': datetime.date(2019, 8, 25)}]}

>>> highlight_from_text("Today is 25th of december")
{'input': ['Today', 'is', '25th', 'of', 'december'], 'matched_pattern': [{'from_index': 2, 'to_index': 4, 'parsed_value': datetime.date(2019, 12, 25)}]}

>>> highlight_from_text("Results are on 23-may-2019 or 24-may-2019")
{'input': ['Results', 'are', 'on', '23-may-2019', 'or', '24-may-2019'], 'matched_pattern': [{'from_index': 3, 'to_index': 3, 'parsed_value': datetime.date(2019, 5, 23)}, {'from_index': 5, 'to_index': 5, 'parsed_value': datetime.date(2019,
 5, 24)}]}

Contributing

Fork and pull request.

Contributors

Jayesh

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

pychronic-0.0.14.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

pychronic-0.0.14-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file pychronic-0.0.14.tar.gz.

File metadata

  • Download URL: pychronic-0.0.14.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.13.0 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.10

File hashes

Hashes for pychronic-0.0.14.tar.gz
Algorithm Hash digest
SHA256 07dc6bc7a7e300c54bca6be2f0ef27cf9ba0daff4d4e01759443da1fc6b2fa45
MD5 ffad9ee7a9371fc6d8a30dc4e96cc859
BLAKE2b-256 1c4ac65e15e2e49a349a75b9a20257a9c409d43489eb2783726d883de55a3b4e

See more details on using hashes here.

File details

Details for the file pychronic-0.0.14-py3-none-any.whl.

File metadata

  • Download URL: pychronic-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.13.0 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.10

File hashes

Hashes for pychronic-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 01abe959518c2cb015cb9dffbc2c5bfcbd166bcd9e9bb0606c1004c6641d240d
MD5 dba5039d2385612ebc14b4ce3d6ba438
BLAKE2b-256 432c905c94b3ddca2feff6f8463528f934e040339cb680bdb7e5917d3c325c43

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