Open
Description
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
Labels
No labels