Time for Humans
Project description
HumanTime
HumanTime
is time for humans in Python.
Sidestep tedious and error-prone code in favor of a simple, English-based DSL for specifying absolute and relative times:
HumanTime.parseTime(Input) | Input
---------------------------+------------------------------------------
2019-05-05 19:32:28.493048 | now
2019-05-05 00:00:00.000000 | today
2019-05-05 12:00:00.000000 | noon
2019-05-04 00:00:00.000000 | yesterday
2019-05-06 00:00:00.000000 | tomorrow
2019-05-06 12:00:00.000000 | tomorrow at noon
2019-05-06 15:30:00.000000 | tomorrow at 3:30PM
2019-05-08 00:00:00.000000 | Wednesday
2019-05-05 22:32:28.493048 | 3hrs from now
2019-05-05 22:31:28.493048 | 1 minute before 3 hours from now
2019-05-05 13:00:00.000000 | an hour after noon
2019-05-05 20:00:00.000000 | eight hours after noon
2019-04-30 00:00:00.000000 | 3 months after 2019-1-31
2021-02-28 00:00:00.000000 | 1 year after 2020-02-29
2019-01-01 00:00:02.000000 | second second after 2019-01-01
2019-06-16 00:00:00.000000 | 1 month after Thurs after 2019-5-9
2019-07-05 00:00:00.000000 | business day after 2019-7-3
2019-07-08 00:00:00.000000 | couple bus days after 2019-7-3
2021-04-04 00:00:00.000000 | Easter 2021
Installation
To install, simply use pip
:
> python3 -m pip install HumanTime
Usage
Behold the simplicity and elegance of HumanTime
--
Times
>>> import HumanTime
>>> HumanTime.parseTime('now')
datetime.datetime(2019, 5, 5, 20, 38, 10, 119936)
>>> HumanTime.parseTime('3 hours from now')
datetime.datetime(2019, 5, 5, 23, 38, 13, 120777)
>>> HumanTime.parseTime('2019-1-3')
datetime.datetime(2019, 1, 3, 0, 0)
>>> HumanTime.parseTime('three days before 2019-1-3')
datetime.datetime(2018, 12, 31, 0, 0)
>>> HumanTime.parseTime('a month after 20200131')
datetime.datetime(2020, 2, 29, 0, 0)
>>> HumanTime.parseTime('Tuesday')
datetime.datetime(2019, 5, 7, 0, 0)
>>> HumanTime.parseTime('wed')
datetime.datetime(2019, 5, 8, 0, 0)
>>> HumanTime.parseTime('Thurs after 2019-5-9')
datetime.datetime(2019, 5, 16, 0, 0)
>>> HumanTime.parseTime('2 business days before 2019-7-8')
datetime.datetime(2019, 7, 3, 0, 0)
Durations
Fixed-length durations, representable by a datetime.timedelta
, may also be parsed:
>>> HumanTime.parseDuration('3 seconds')
datetime.timedelta(seconds=3)
>>> HumanTime.parseDuration('3 minutes')
datetime.timedelta(seconds=180)
>>> HumanTime.parseDuration('3 days')
datetime.timedelta(days=3)
>>> HumanTime.parseDuration('three weeks')
datetime.timedelta(days=21)
Numbers
Simple numbers (those necessary for parsing times) can also be parsed separately:
>>> HumanTime.parseCardinal('four')
4
>>> HumanTime.parseOrdinal('fourth')
4
>>> HumanTime.parseNumber('20th')
20
>>> HumanTime.parseNumber('45')
45
Tools
Common actions are packaged as CLI tools and can be found in the HumanTime.Tools
module.
GenerateHolidayCalendar
Generates a holiday calendar CSV with optional from and to years, headers, and observance rules.
> python3 -m HumanTime.Tools.GenerateHolidayCalendar -f 2020 -t 2021 -o
Date,Country,Name
2020-01-01,US,New Year's Day
2020-01-20,US,Martin Luther King Jr. Day
2020-02-17,US,Presidents' Day
2020-04-10,US,Good Friday
2020-05-25,US,Memorial Day
2020-07-03,US,Independence Day (Observed)
2020-09-07,US,Labor Day
...
Development
Unit Tests
Unit tests can be run with the following command:
> python3 -m unittest discover
...........................................................................
----------------------------------------------------------------------
Ran 75 tests in 0.020s
OK
CI
Continuous integration is handled in Gitlab CI via .gitlab-ci.yml
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file HumanTime-0.1.15.tar.gz
.
File metadata
- Download URL: HumanTime-0.1.15.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71a80ac5c241e0d5e89783091a92615aa06365f736011bf8fe1aac9a8e49d986 |
|
MD5 | 21ad7744a8bb9593bcb02b4271614b58 |
|
BLAKE2b-256 | a15f1a1a2dac0843f05db051a56f9e24e14cc3bec82bc72fdc814e21b3a9ce13 |
File details
Details for the file HumanTime-0.1.15-py3-none-any.whl
.
File metadata
- Download URL: HumanTime-0.1.15-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62f25e2587139234ea0ba16585f7cdf2131ddfd3862457651114055a087692c2 |
|
MD5 | c8afe1ff7f778be278f49fabadb8c788 |
|
BLAKE2b-256 | df64d90e9f7dbf2771b4caad106ea83c667ba3eea390270c25c6ebb7d595323c |