[issue4291] Allow Division of datetime.timedelta Objects
Jeremy Banks jer...@jeremybanks.ca added the comment: Redundant with #2706 and others. -- nosy: -belopolsky, haypo, marketdickinson status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4291 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4291] Allow Division of datetime.timedelta Objects
STINNER Victor victor.stin...@haypocalc.com added the comment: See related issues: #1289118 and #2706. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4291 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4291] Allow Division of datetime.timedelta Objects
Mark Dickinson [EMAIL PROTECTED] added the comment: [Christian] float(td1) / float(td2) which is far more obvious than td1 / td2 To me, td1/td2 is more obvious that float(td1)/float(td2). float(td) involves an arbitrary choice, to return time in *seconds* (rather than days, or milliseconds, or ...); I think this violates EIBTI. To me, the obvious and easy-to-read way to get the number of seconds is to do the division: seconds_in_td = td1 / timedelta(seconds = 1) -- nosy: +marketdickinson ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4291 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4291] Allow Division of datetime.timedelta Objects
Alexander Belopolsky [EMAIL PROTECTED] added the comment: @Christian Adding a __float__ method to datetime was entertained back in 2003, but was rejected. The same reasons apply to timedelta: - A C double doesn't have enough precision for roundtrip guarantees. - Does it really need to be automatic? I.e., does it really need to be __float__()? I'd be less against this if it was an explicit method, e.g. dt.asposixtime(). --Guido van Rossum (home page: http://www.python.org/~guido/) http://mail.python.org/pipermail/python-dev/2003-January/032166.html -- nosy: +belopolsky ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4291 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4291] Allow Division of datetime.timedelta Objects
STINNER Victor [EMAIL PROTECTED] added the comment: I don't understand what do you expect with the divison. Can you give an use case and/or examples? -- nosy: +haypo ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4291 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4291] Allow Division of datetime.timedelta Objects
Jeremy Banks [EMAIL PROTECTED] added the comment: Sorry, allowing for conversion to int/float is probably a more sensible solution. This idea was brought to my mind when I was making a very very simple script for a friend to display how far through a time range we currently are. For example: elapsed = datetime.timedelta(hours=4, days=3) duration = datetime.timedelta(days=30) percentage = (100 * elapsed / duration) In my case, precision wasn't important so I just divided elapsed.days by duration.days, but it would be continent to have an accurate result by just writing what I did above. ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4291 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4291] Allow Division of datetime.timedelta Objects
New submission from Jeremy Banks [EMAIL PROTECTED]: It would be convenient if it were possible to divide one datetime.timedelta object by another to determine their relative durations. Were the datetime module pure Python a crude solution would just be to add two methods like this: def toMicroseconds(self): return ((self.days * 24 * 60) + self.seconds * 100) + self.microseconds def __truediv__(self, other): return self.toMicroseconds() / other.toMicroseconds() However, I don't understand know the Python C API well enough to know how to patch the C module. -- components: Library (Lib) messages: 75670 nosy: Jeremy Banks severity: normal status: open title: Allow Division of datetime.timedelta Objects type: feature request ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4291 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4291] Allow Division of datetime.timedelta Objects
STINNER Victor [EMAIL PROTECTED] added the comment: The issue #1673409 may help: delta1.toseconds() / delta2.toseconds(). ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4291 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4291] Allow Division of datetime.timedelta Objects
Jeremy Banks [EMAIL PROTECTED] added the comment: Thanks, I should have paid more attention to the results when I searched for duplicates. I think that Christian's suggestion of enabling float() and int() for timedeltas is worth having here, though. -- nosy: -christian.heimes ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4291 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4291] Allow Division of datetime.timedelta Objects
Christian Heimes [EMAIL PROTECTED] added the comment: That's just too weird. A long time ago I suggested to implement __int__ and __float__ on timedelta objects: int(timedelta) - seconds, float(timedelta) - seconds.micros. Then your use case could be written as float(td1) / float(td2) which is far more obvious than td1 / td2. Unfortunately I wasn't a core developer back in those days. -- nosy: +christian.heimes priority: - low ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4291 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com