Datetime Helpers
A handy collection of datetime utils.
Install
Install and update using pip.
$ pip install -U datetime-helpers
What's available?
import datetime_helpers
# Given a datetime:
>>> dt = datetime.date(2017, 4, 17)
# Check the day of week
>>> datetime_helpers.get_day_of_week(dt=dt)
'Monday'
# Check if it is a weekend
>>> datetime_helpers.is_weekend(dt=dt)
False
# Check if it is a weekday
>>> datetime_helpers.is_weekday(dt=dt)
True
# Get the previous business day
>>> datetime_helpers.get_previous_business_day(dt=dt)
datetime.date(2017, 4, 14)
# Get the next business day
>>> datetime_helpers.get_next_business_day(dt=dt)
datetime.date(2017, 4, 18)
# Get the first business day of the month
>>> datetime_helpers.get_first_business_day_of_month(dt=dt)
datetime.date(2017, 4, 3)
# Get the nth business day of the month
>>> n = 3 # e.g. third business day
>>> datetime_helpers.get_nth_business_day_of_month(dt=dt, n=n)
datetime.date(2017, 4, 5)
# Convert to a datetime string with custom format (defaults to JSON date format)
>>> datetime_helpers.datetime_to_string(dt=dt)
'2017-04-17T00:00:00.000000Z'
# Convert to a date string with custom format (defaults to YYYY-MM-DD)
>>> datetime_helpers.date_to_string(dt=dt)
'2017-04-17'
# Convert a string with custom format to datetime (defaults to JSON date format)
>>> text = '2016-04-17T00:00:00.000000Z'
>>> datetime_helpers.datetime_from_string(text=text)
datetime.datetime(2016, 4, 17, 0, 0)
# Convert a string with custom format to datetime (defaults to JSON date format)
>>> text = '2016-04-17T00:00:00.000000Z'
>>> datetime_helpers.datetime_from_string(text=text)
datetime.datetime(2016, 4, 17, 0, 0)
# Convert a windows filetime to datetime
>>> windows_filetime = 116444736000000000
>>> datetime_helpers.datetime_from_windows_filetime(windows_filetime=windows_filetime)
datetime.datetime(1970, 1, 1, 0, 0)
# Convert to seconds
>>> datetime_helpers.datetime_to_seconds(dt=dt)
1492387200.0
# Convert seconds to datetime
>>> seconds = 1492387200
>>> datetime_helpers.datetime_from_seconds(seconds=seconds)
datetime.datetime(2017, 4, 17, 0, 0)
# Convert to millis
>>> datetime_helpers.datetime_to_millis(dt=dt)
1492387200000
# Convert millis to datetime
>>> millis = 1492387200000
>>> datetime_helpers.datetime_from_millis(millis=millis)
datetime.datetime(2017, 4, 17, 0, 0)
# Convert date to datetime
>>> datetime_helpers.datetime_from_date(dt=dt)
datetime.datetime(2017, 4, 17, 0, 0)
Contributing
Contributions are welcome via pull requests.
First time setup
$ git clone git@github.com:DeveloperRSquared/datetime-helpers.git
$ cd datetime-helpers
$ poetry install
$ poetry shell
Tools including black, mypy etc. will run automatically if you install pre-commit using the instructions below
$ pre-commit install
$ pre-commit run --all-files
Running tests
$ poetry run pytest
Links
- Source Code: https://github.com/DeveloperRSquared/datetime-helpers/
- PyPI Releases: https://pypi.org/project/datetime-helpers/
- Issue Tracker: https://github.com/DeveloperRSquared/datetime-helpers/issues/
Metadata
Release files for datetime-helpers 0.0.14
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| datetime-helpers-0.0.14.tar.gz | 6.3 kB | Without provenance | Details for datetime-helpers-0.0.14.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| datetime_helpers-0.0.14-py3-none-any.whl | Python 3 | none | any | Details for datetime_helpers-0.0.14-py3-none-any.whl |
Total release size: 12.5 kB
Release files / datetime-helpers-0.0.14.tar.gz
| Download URL | datetime-helpers-0.0.14.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fec0a11afc75b8f3fee6417c1cd564b02e1a724cd8e05f4b1e21e4d4eeefa009
|
|
BLAKE2b-256 checksum How to use checksums |
5f41cbc9ae74a94f56ef12c18e1b2a17ff2a58419f6a04901a9e40fe90b12269
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.10.2 Linux/5.11.0-1027-azure
|
Release files / datetime_helpers-0.0.14-py3-none-any.whl
| Download URL | datetime_helpers-0.0.14-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
291c3795ad04cc223185c21e7b2c32496de87f48b2fabf1b8a8288db1c7ae4a5
|
|
BLAKE2b-256 checksum How to use checksums |
2f64b953d23e461a611acf708655dc7930d16191aa7ec60421c205f47bf1aace
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.10.2 Linux/5.11.0-1027-azure
|
Security for datetime-helpers 0.0.14
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.