{"id":7790,"library":"timedelta","title":"timedelta","description":"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.","status":"abandoned","version":"2020.12.3","language":"en","source_language":"en","source_url":"https://github.com/andrewp-as-is/timedelta.py","tags":["datetime","time","utility","duration","unmaintained"],"install":[{"cmd":"pip install timedelta","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The library is imported as a module 'timedelta', and its main class is 'Timedelta' within that module. Direct import of 'Timedelta' from 'timedelta' as a package is incorrect for this library's structure.","wrong":"from timedelta import Timedelta","symbol":"Timedelta","correct":"import timedelta\ntd_obj = timedelta.Timedelta(...)"},{"note":"Using `import timedelta` will shadow Python's standard `datetime` module and prevent access to `datetime.timedelta`. If you need both, use `from datetime import timedelta` and `import timedelta as td_lib` to differentiate.","wrong":"import timedelta\ntd_obj = timedelta(...)","symbol":"datetime.timedelta (standard library)","correct":"from datetime import timedelta"}],"quickstart":{"code":"import timedelta\nfrom datetime import datetime, timedelta as stdlib_timedelta\n\n# Using the third-party timedelta library's Timedelta class\ntd_library_obj = timedelta.Timedelta(days=2, hours=2)\nprint(f\"Library Timedelta: {td_library_obj}\")\n\n# Example of initializing from a standard library timedelta difference\nnow = datetime.now()\nthen = now - stdlib_timedelta(days=1, minutes=30)\ndiff_from_stdlib = now - then\ntd_from_diff = timedelta.Timedelta(diff_from_stdlib)\nprint(f\"Library Timedelta from stdlib diff: {td_from_diff}\")\nprint(f\"Days: {td_from_diff.days}, Hours: {td_from_diff.hours}\")\n","lang":"python","description":"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`."},"warnings":[{"fix":"It is strongly recommended to use Python's built-in `datetime.timedelta` for time difference operations, or other actively maintained third-party libraries like `python-dateutil` for advanced features. Avoid this library for new projects.","message":"The `timedelta` library has not been updated since December 2020. It is effectively unmaintained and likely incompatible with newer Python versions or may contain unpatched security vulnerabilities.","severity":"breaking","affected_versions":"<=2020.12.3"},{"fix":"Always use `from datetime import timedelta` for the standard library's timedelta. If you must use this specific third-party library, consider importing it with an alias, e.g., `import timedelta as custom_timedelta`, to prevent naming conflicts.","message":"This library installs a module named `timedelta`, which directly clashes with and shadows Python's standard `datetime` module when using `import timedelta`. This can lead to significant confusion and unexpected behavior, as users often expect `datetime.timedelta` functionality.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Thoroughly test any code that attempts to use `timedelta.Timedelta` interchangeably with `datetime.timedelta`. For reliable and complete functionality, prioritize `datetime.timedelta`.","message":"Despite being described as a 'replacement,' the `Timedelta` class from this library may not fully replicate all methods, attributes, or arithmetic behaviors of `datetime.timedelta`. Expecting full interchangeability can lead to subtle bugs.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `pip install timedelta` for this specific library. The correct import for this library's class is `import timedelta` followed by `timedelta.Timedelta(...)`. If you intended to use the standard library, use `from datetime import timedelta`.","cause":"You are either using a different `timedelta` library, or you incorrectly tried to access `Timedelta` from the `datetime` module after a conflicting import, or you attempted `from timedelta import Timedelta` for this library.","error":"AttributeError: module 'timedelta' has no attribute 'Timedelta'"},{"fix":"The library's `Timedelta` class is shown to be initialized with `datetime1 - datetime2`, implying it consumes the result of `datetime.timedelta` difference. If you need direct arithmetic with `datetime.datetime` objects, stick to the standard library: `from datetime import datetime, timedelta` and use `datetime_obj + timedelta_obj`.","cause":"You are attempting arithmetic operations (like subtraction from `datetime.datetime`) with the `Timedelta` class from this third-party library, and it might not fully support or correctly implement the expected operand types, or its internal representation differs from `datetime.timedelta`.","error":"TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'timedelta.Timedelta'"}]}