Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplying relativedelta with fractional days ends up with truncated values #1318

Open
jrmylow opened this issue Nov 12, 2023 · 0 comments
Open

Comments

@jrmylow
Copy link

jrmylow commented Nov 12, 2023

Multiplying a relativedelta with non-integer day values (e.g. relativedelta(days=+1.5) converts to integer values of days, losing information in the process.

The cause appears to be applying a blanket int() to the results of the multiplication L495, without checking to see if fractional days should be converted down into hours/seconds etc.

Is this intended behaviour? Currently relativedelta accepts non-integer values for days (as does the python standard library), so my current assumption is that it should mirror the behaviour from datetime and convert fractional days.

Minimal reproducible example:

import dateutil
delta = dateutil.relativedelta.relativedelta(days=1.5)
print(delta) # relativedelta(days=+1.5)
print(delta * 1) # relativedelta(days=+1)

By contrast, datetime.timedelta from the standard library does not lose the half-day:

import datetime
delta = datetime.timedelta(days=1.5)
print(delta) # datetime.timedelta(days=1, seconds=43200)
print(delta * 1) # datetime.timedelta(days=1, seconds=43200)

Dateutil version: 2.8.2
Python version: 3.10.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant