Skip to content

isoformat handles negative timezone offset incorrectly #52

Description

@bkeryan

The hightime.datetime implementation of isoformat expects the timezone to have a plus sign. When the timezone has a minus sign, it doesn't split the timezone before adding the femtoseconds and yoctoseconds, so you end up with a timezone in the middle of the string.

Steps to reproduce:

>>> import datetime as dt, hightime as ht
>>> dt.datetime(2025,1,1,tzinfo=dt.timezone(dt.timedelta(hours=-1))).isoformat()
'2025-01-01T00:00:00-01:00'
>>> ht.datetime(2025,1,1,tzinfo=dt.timezone(dt.timedelta(hours=-1))).isoformat()
'2025-01-01T00:00:00-01:00'
>>> ht.datetime(2025,1,1,yoctosecond=40,tzinfo=dt.timezone(dt.timedelta(hours=-1))).isoformat()
'2025-01-01T00:00:00-01:00.000000000000000000000040'

Expected output:

'2025-01-01T00:00:00.000000000000000000000040-01:00'

Note that the fix is not as easy as using minus instead of plus, because the string may contain other minus signs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions