Skip to content

Add timespec argument to to_iso8601_string() #347

Open
@joaonc

Description

@joaonc

In Python 3.6, the timespec argument was added to datetime.isoformat(...) and for good reason: depending on whether or not the datetime object has milliseconds, the isoformat() method returns a different structured string.

Pendulum's to_iso8601_string() has the same issue.

Here's how I resolved it:

    iso_8601 = dt.to_iso8601_string()
    if len(iso_8601) > 25:
        # Contains microseconds and milliseconds. Remove.
        iso_8601 = iso_8601[:19] + iso_8601[26:]

    return iso_8601

However, I think this type of workaround (hack, really) should not be needed and the option to return only to a certain precision (hours, minutes, seconds, milliseconds and microseconds) should be supported in pendulum, as it is in datetime.

Note: this issue is similar to #191 but I think things changed since then, given the support of this feature by Python AND the fact that there are real world scenarios where it's needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions