Skip to content

Add timespec argument to to_iso8601_string() #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
joaonc opened this issue Feb 26, 2019 · 0 comments · May be fixed by #353
Open

Add timespec argument to to_iso8601_string() #347

joaonc opened this issue Feb 26, 2019 · 0 comments · May be fixed by #353

Comments

@joaonc
Copy link

joaonc commented Feb 26, 2019

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.

@Itay4 Itay4 linked a pull request Mar 9, 2019 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant