Skip to content

timedelta_isoformat does not produce correct string in some cases #3899

Closed
@07pepa

Description

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

   pydantic version: 1.9.0
            pydantic compiled: True
                 install path: C:\Program Files\Python310\Lib\site-packages\pydantic
               python version: 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)]
                     platform: Windows-10-10.0.19044-SP0
     optional deps. installed: ['dotenv', 'typing-extensions']

Code Demonstration bug

from pydantic.json import timedelta_isoformat
from datetime import datetime

timedelta = (datetime.fromisoformat("2022-03-15 08:00:57.152735+00:00") -
             datetime.fromisoformat("2022-03-15 08:00:57.264000+00:00"))

incorrect_iso_string = timedelta_isoformat(timedelta)
# this produce "P-1DT23H59M59.888735S"  and that is incorrect according to documentation ([±]P[DD]DT[HH]H[MM]M[SS]S)
...

i have verified this on two diferent computers with two diferents setups (conda/regular python so it should not be problem of my enviroment)

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions