Skip to content

Commit fc33b9f

Browse files
committed
Change representation of UTC datetime in to_iso8601_string()
1 parent 0c5c84e commit fc33b9f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

pendulum/datetime.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,12 @@ def to_iso8601_string(self):
328328
329329
:rtype: str
330330
"""
331-
return self._to_string('iso8601')
331+
string = self._to_string('iso8601')
332+
333+
if self.tz and self.tz.name == 'UTC':
334+
string = string.replace('+00:00', 'Z')
335+
336+
return string
332337

333338
def to_rfc822_string(self):
334339
"""

tests/datetime/test_strings.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55

66
def test_to_string():
7-
d = pendulum.datetime(1975, 12, 25, 0, 0, 0, 0)
7+
d = pendulum.datetime(1975, 12, 25, 0, 0, 0, 0, tz='local')
88
assert str(d) == d.to_iso8601_string()
9-
d = pendulum.datetime(1975, 12, 25, 0, 0, 0, 123456)
9+
d = pendulum.datetime(1975, 12, 25, 0, 0, 0, 123456, tz='local')
1010
assert str(d) == d.to_iso8601_string()
1111

1212

@@ -43,6 +43,11 @@ def test_to_iso8601_string():
4343
assert d.to_iso8601_string() == '1975-12-25T14:15:16-05:00'
4444

4545

46+
def test_to_iso8601_string_utc():
47+
d = pendulum.datetime(1975, 12, 25, 14, 15, 16)
48+
assert d.to_iso8601_string() == '1975-12-25T14:15:16Z'
49+
50+
4651
def test_to_iso8601_extended_string():
4752
d = pendulum.datetime(1975, 12, 25, 14, 15, 16, 123456, tz='local')
4853
assert d.to_iso8601_string() == '1975-12-25T14:15:16.123456-05:00'

0 commit comments

Comments
 (0)