timedelta

2020.12.3 · abandoned · verified Thu Apr 16

The `timedelta` library, last updated in 2020, provides a custom `Timedelta` class intended as a replacement for Python's standard `datetime.timedelta`. It aims to offer similar functionality for representing durations and performing time arithmetic, but its development appears to be inactive. The current version is 2020.12.3.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and instantiate the `Timedelta` class from the `timedelta` library, including an example of creating one from a difference calculated using the standard `datetime.timedelta`.

import timedelta
from datetime import datetime, timedelta as stdlib_timedelta

# Using the third-party timedelta library's Timedelta class
td_library_obj = timedelta.Timedelta(days=2, hours=2)
print(f"Library Timedelta: {td_library_obj}")

# Example of initializing from a standard library timedelta difference
now = datetime.now()
then = now - stdlib_timedelta(days=1, minutes=30)
diff_from_stdlib = now - then
td_from_diff = timedelta.Timedelta(diff_from_stdlib)
print(f"Library Timedelta from stdlib diff: {td_from_diff}")
print(f"Days: {td_from_diff.days}, Hours: {td_from_diff.hours}")

view raw JSON →