Skip to content

Commit 94ba8c4

Browse files
authored
model: refactor the fix for Edm.DateTimeOffset.from_json()
Use solution provided in issue #202 by @squeakyboots (#233)
1 parent e28b3ca commit 94ba8c4

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

pyodata/v2/model.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,15 +530,16 @@ def to_json(self, value):
530530

531531
def from_json(self, value):
532532
# special edge case:
533-
# datetimeoffset'yyyy-mm-ddThh:mm[:ss]' = defaults to UTC, when offset value is not provided in responde data by service but the metadata is EdmDateTimeOffset
533+
# datetimeoffset'yyyy-mm-ddThh:mm[:ss]' = defaults to UTC, when offset value is not provided in response
534+
# by service, but the metadata is EdmDateTimeOffset
534535
# intentionally just for from_json, generation of to_json should always provide timezone info
535-
if re.match(r"^/Date\((?P<milliseconds_since_epoch>-?\d+)\)/$", value):
536-
value = value.replace(')', '+0000)')
537-
538-
matches = re.match(r"^/Date\((?P<milliseconds_since_epoch>-?\d+)(?P<offset_in_minutes>[+-]\d+)\)/$", value)
536+
matches = re.match(r"^/Date\((?P<milliseconds_since_epoch>-?\d+)(?P<offset_in_minutes>[+-]\d+)?\)/$", value)
539537
try:
540538
milliseconds_since_epoch = matches.group('milliseconds_since_epoch')
541-
offset_in_minutes = int(matches.group('offset_in_minutes'))
539+
if matches.group('offset_in_minutes') is not None:
540+
offset_in_minutes = int(matches.group('offset_in_minutes'))
541+
else:
542+
offset_in_minutes = 0
542543
except (ValueError, AttributeError):
543544
raise PyODataModelError(
544545
f"Malformed value {value} for primitive Edm.DateTimeOffset type."

0 commit comments

Comments
 (0)