classification
Title: Allow multiplying timedelta by Decimal
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Allow using decimals as arguments to `timedelta`
View: 14262
Assigned To: Nosy List: belopolsky, cool-RR, mark.dickinson
Priority: normal Keywords:

Created on 2012-09-19 18:23 by cool-RR, last changed 2012-09-19 18:58 by mark.dickinson. This issue is now closed.

Messages (8)
msg170737 - (view) Author: Ram Rachum (cool-RR) * Date: 2012-09-19 18:23
Please allow multiplying timedelta by a Decimal:

Python 3.3.0a1 (default, Mar  4 2012, 17:27:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> import decimal
>>> decimal.Decimal('0.1')*datetime.timedelta(seconds=3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for *: 'Decimal' and 'datetime.timedelta'
>>>
msg170739 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-09-19 18:35
Do you have a particular use-case in mind?  Is there a reason that td * 0.1 or td / 10.0 aren't good enough?
msg170740 - (view) Author: Ram Rachum (cool-RR) * Date: 2012-09-19 18:41
This is for cases where I already have the number as a Decimal. Asking me to convert it to `float` myself is annoying.
msg170742 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2012-09-19 18:50
This is similar to issue 14262.  If we decide that timedelta should play nice with Decimal, I would like to consider all related features.
msg170743 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-09-19 18:52
> Asking me to convert it to `float` myself is annoying.

Well, it's just a call to 'float', right?  On the other side, we're looking at significant extra code to implement Decimal * timedelta, so there needs to be a good reason to add it.  (And there's feature-creep involved, too;  once we've got Decimal * timedelta, there will probably also be requests for timedelta / Decimal, and possibly timedelta / timedelta -> Decimal too).
msg170744 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2012-09-19 18:54
In fact, this is a near-duplicate of #14262 becaus instead of

>>> decimal.Decimal('0.1')*datetime.timedelta(seconds=3)

one can always write

>>> datetime.timedelta(seconds=decimal.Decimal('0.1')*3)
msg170745 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-09-19 18:54
Agreed; +1 on folding this into issue 14262.
msg170747 - (view) Author: Ram Rachum (cool-RR) * Date: 2012-09-19 18:57
+1 on folding this into issue 14262.
History
Date User Action Args
2012-09-19 18:58:00mark.dickinsonsetstatus: open -> closed
superseder: Allow using decimals as arguments to `timedelta`
resolution: duplicate
2012-09-19 18:57:08cool-RRsetmessages: + msg170747
2012-09-19 18:54:59mark.dickinsonsetmessages: + msg170745
2012-09-19 18:54:13belopolskysetmessages: + msg170744
2012-09-19 18:52:47mark.dickinsonsetmessages: + msg170743
2012-09-19 18:50:16belopolskysetmessages: + msg170742
versions: - Python 3.3
2012-09-19 18:47:04mark.dickinsonsetnosy: + belopolsky
2012-09-19 18:41:17cool-RRsetmessages: + msg170740
2012-09-19 18:35:58mark.dickinsonsetnosy: + mark.dickinson
messages: + msg170739
2012-09-19 18:23:26cool-RRcreate