Skip to content

Consistent handling of parsing ns resolution timestamps with and without ciso8601 #127

@ddn0

Description

@ddn0

I noticed that the behavior of parsing timestamps in aiochclient wrt nanosecond resolution timestamps depends on whether ciso8601 is installed.

import ciso8601
import datetime

ciso8601.parse_datetime('2014-12-05 12:30:45.123456000')
# datetime.datetime(2014, 12, 5, 12, 30, 45, 123456)

datetime.datetime.strptime('2014-12-05 12:30:45.123456000', '%Y-%m-%d %H:%M:%S.%f')
# raises ValueError: unconverted data remains: 000

I understand that using ciso8601 is a performance optimization, but it is a little counterintuitive to me that aiochclient's functional behavior varies due to the present or absence of a library. At the very least, it might be good to document this.

FWIW, for Python >= 3.11, there is a better standard library fallback:

datetime.datetime.fromisoformat('2014-12-05 12:30:45.123456000')
# datetime.datetime(2014, 12, 5, 12, 30, 45, 123456)

Happy to contribute a PR if you give me some guidance as to the expectations of aiochclient around parsing timestamps in general.

Thanks so much for your work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions