Hi, thanks so much for your work on pendulum. Much better so far than other alternatives I've been using for way too long.
It appears the iso8601 timezone designator Z is handled inconsistently between between parsing and rendering of datetimes to/from iso8601 strings.
On rendering a UTC-datetime to an iso8601 string, the timezone will be correctly represented as Z. Ex:
>>> pendulum.now('utc').to_iso8601_string()
'2020-02-05T20:05:37.364951Z'
However, on parsing an iso8601 string, Z is not parsed as UTC... it's parsed as Timezone('+00:00') timezone.
>>> pendulum.parse('2020-02-05T20:05:37.364951Z')
DateTime(2020, 2, 5, 20, 5, 37, 364951, tzinfo=Timezone('+00:00'))
This results in some inconsistencies when rendering & parsing back and forth from strings:
>>> now_iso_str = pendulum.now('utc').to_iso8601_string()
>>> now_iso_str
'2020-02-05T20:48:06.814968Z'
>>> now_iso_str_2 = pendulum.parse(now_iso_str).to_iso8601_string()
>>> now_iso_str_2
'2020-02-05T20:48:06.814968+00:00'
>>> now_iso_str == now_iso_str_2
False
I would propose that when parsing an iso8601 string, Z should be parsed directly to Timezone('UTC') rather than to Timezone('+00:00')
If this sounds like a change you would be open to @sdispater , let me know and I'll prepare a PR with tests. Cheers.
Hi, thanks so much for your work on pendulum. Much better so far than other alternatives I've been using for way too long.
It appears the iso8601 timezone designator
Zis handled inconsistently between between parsing and rendering of datetimes to/from iso8601 strings.On rendering a UTC-datetime to an iso8601 string, the timezone will be correctly represented as
Z. Ex:However, on parsing an iso8601 string,
Zis not parsed as UTC... it's parsed asTimezone('+00:00')timezone.This results in some inconsistencies when rendering & parsing back and forth from strings:
I would propose that when parsing an iso8601 string,
Zshould be parsed directly toTimezone('UTC')rather than toTimezone('+00:00')If this sounds like a change you would be open to @sdispater , let me know and I'll prepare a PR with tests. Cheers.