[New-bugs-announce] [issue38701] datetime.timedelta string representation is ambiguous

Serge Matveenko report at bugs.python.org
Tue Nov 5 10:48:39 EST 2019


New submission from Serge Matveenko <serge at matveenko.ru>:

Negative `timedelta` string representation is ambiguous.

```
>>> from datetime import datetime, timedelta
>>> d2 = datetime.now()
>>> d1 = d2 - timedelta(days=42, seconds=5)
>>> str(d2 - d1)
'42 days, 0:00:05'
>>> str(d1 - d2)
'-43 days, 23:59:55'
```

I would expect `str(d1 - d2)` to be one of the following:
* '-42 days, 0:00:05'
* '-(42 days, 0:00:05)'
* '- 42 days, 0:00:05'

----------
components: Library (Lib)
messages: 356041
nosy: lig
priority: normal
severity: normal
status: open
title: datetime.timedelta string representation is ambiguous
type: behavior
versions: Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38701>
_______________________________________


More information about the New-bugs-announce mailing list