Skip to content

Duration division, multiplication and mod broken for month lengths. #799

Description

@gazpachoking
  • I am on the latest Pendulum version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • OS Version: Windows 11
  • Pendulum version: 3.0.0

Issue

When doing math on Duration objects, months are ignored. This is because it uses the _to_microseconds method which ignores the months attribute.
https://github.com/sdispater/pendulum/blob/3e3fec6a5b66759078c5ae39c736ca95b78adbef/src/pendulum/duration.py#L356-L357
e.g. :

>>> pendulum.Duration(years=1)/pendulum.Duration(months=1)
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2022.2.2\plugins\python\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "C:\Users\chase\PycharmProjects\Flexget\py310\lib\site-packages\pendulum\duration.py", line 419, in __truediv__
    float, usec / other._to_microseconds()  # type: ignore[attr-defined]
ZeroDivisionError: division by zero

>>> pendulum.Duration(months=1)*3.0
Duration()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions