Skip to content

Commit 2571a33

Browse files
committed
Fix issue #28
Change representation of timestamps to remove incorrect "Z" suffix for non-UTC timestamps.
1 parent 2666a6e commit 2571a33

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/celpy/celtypes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,10 @@ def __repr__(self) -> str:
10981098
return f"{self.__class__.__name__}({str(self)!r})"
10991099

11001100
def __str__(self) -> str:
1101-
return self.strftime("%Y-%m-%dT%H:%M:%SZ")
1101+
text = self.strftime("%Y-%m-%dT%H:%M:%S%z")
1102+
if text.endswith("+0000"):
1103+
return f"{text[:-5]}Z"
1104+
return f"{text[:-2]}:{text[-2:]}"
11021105

11031106
def __add__(self, other: Any) -> 'TimestampType':
11041107
"""Timestamp + Duration -> Timestamp"""

tests/test_celtypes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,17 @@ def test_timestamp_type():
339339
assert ts_1.getSeconds() == IntType(30)
340340

341341

342+
def test_timestamp_type_issue_28():
343+
utc = TimestampType('2020-10-20T12:00:00Z')
344+
not_utc = TimestampType('2020-10-20T12:00:00-05:00')
345+
346+
assert repr(utc) == "TimestampType('2020-10-20T12:00:00Z')"
347+
assert repr(not_utc) == "TimestampType('2020-10-20T12:00:00-05:00')"
348+
349+
assert utc != not_utc
350+
assert str(utc) != str(not_utc)
351+
352+
342353
def test_extended_timestamp_type():
343354
others = {
344355
'et': 'US/Eastern',

type_check/lineprecision.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ celpy.__main__ 465 172 7 42 244 0
55
celpy.adapter 137 35 3 9 85 5
66
celpy.c7nlib 1584 340 15 154 1075 0
77
celpy.celparser 402 208 2 23 169 0
8-
celpy.celtypes 1500 435 14 221 791 39
8+
celpy.celtypes 1503 438 14 221 791 39
99
celpy.evaluation 2471 839 33 176 1408 15
1010
xlate 0 0 0 0 0 0
1111
xlate.c7n_to_cel 1730 387 102 145 1091 5

0 commit comments

Comments
 (0)