python time duration conversion module
Project description
python time duration conversion module
Installation
pip install duration
Usage
Examples below show how to convert timestamps in hh:mm:ss and mm:ss format to iso8601 strings, integer seconds, datetime.timedelta objects and (hours, minutes, seconds,) deltas
from duration import (
to_iso8601,
to_seconds,
to_timedelta,
to_tuple,
)
time = '1:23:45'
iso8601 = to_iso8601(time) # 'PT01H23M45S'
seconds = to_seconds(time) # 5025
td = to_timedelta(time) # timedelta(hours=1, minutes=23, seconds=45)
tuple_ = to_tuple(time) # (1, 23, 45,)
Examples above use strict mode by default. In strict mode, conversion functions raise StrictnessError if your duration string meets one of the following conditions:
hh > 23
mm > 59
ss > 59
To disable strict mode, pass strict=False to the conversion function
from duration import (
to_iso8601,
to_seconds,
to_timedelta,
to_tuple,
)
time = '24:83:25'
iso8601 = to_iso8601(time, strict=False) # 'P1DT01H23M25S'
seconds = to_seconds(time, strict=False) # 91405
td = to_timedelta(time, strict=False) # timedelta(seconds=91405)
tuple_ = to_tuple(time, strict=False) # (25, 23, 25,)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file duration-1.1.1.tar.gz.
File metadata
- Download URL: duration-1.1.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5eb44e3bd829726937803a9c6e80e102dee1e14b153530bc5c6b65ced3a934bc
|
|
| MD5 |
d06d3939509daeecd919fcdc49c08bc4
|
|
| BLAKE2b-256 |
66252ce4bb6dff9c3a3989c35f89876ddbc0fb56fc8e2cf07a7add840521145a
|
File details
Details for the file duration-1.1.1-py3-none-any.whl.
File metadata
- Download URL: duration-1.1.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ef455d5dccc3933b45d1af54bca837240fd185fe24da259df34865d78749960
|
|
| MD5 |
29a9737fde2ea166a571e162b28c63a6
|
|
| BLAKE2b-256 |
6b70eccf8b3115bf458997ae0f15da9d571deb827b252010cf703ae92d2a9739
|