Simple and easy to use time-related utility functions
Project description
Chronos
Simple and easy to use time-related utility functions.
These are simple routines we caught ourselves constantly in need when developing projects in Hackt. They're all a combination of native Python libraries that we wanted to standardize in a standlone library.
Usage
Install from PyPI:
pip install python_chronos
Import in your project(s):
import chronos
Get current UTC timestamp (datetime
type)
chronos.utc_now()
# datetime.datetime(2021, 2, 2, 3, 59, 11, 856368)
UTC timestamp (integer
type)
chronos.utc_timestamp()
# 1612238428
Past/Future UTC (datetime
type)
The following function adds 10 minutes to the current UTC datetime:
chronos.future_utc_datetime(minutes=10)
# datetime.datetime(2021, 2, 2, 4, 14, 3, 573054)
Similarly, the past_utc_datetime
function does exactly what you have in mind:
chronos.past_utc_datetime(minutes=10)
# datetime.datetime(2021, 2, 2, 3, 54, 3, 573054)
Any keyword arguments you would pass to datetime.timedelta
will work with future_utc_datetime
and past_utc_datetime
.
Past/Future UTC in UNIX timestamp (integer
type)
chronos.future_utc_timestamp(hours=2)
# 1612246043
Analogously, the past_utc_timestamp
function will do exactly what you expect:
chronos.past_utc_timestamp(hours=2)
# 1612238843
Again, any keyword arguments you would pass to datetime.timedelta
will work with future_utc_timestamp
and past_utc_timestamp
.
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 Distributions
Built Distribution
Hashes for python_chronos-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9691b6f74d7e364d20f45f1e2afdac9cd34a0a7fa8d17a2b9f8508d07095854 |
|
MD5 | e0f2ddf2c4cb0c183eebe2c1a3b405dc |
|
BLAKE2b-256 | 246ecd7ebc7e5a3db80d5b5aeb736bf64925581a83be55db00384009094f7bd8 |