Skip to content

Commit b02460e

Browse files
committed
add datetime regex per gemini comment
1 parent 80d7a64 commit b02460e

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

sdks/python/apache_beam/yaml/yaml_mapping.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ def __setstate__(self, state):
8181

8282
_js_contexts = _JsThreadContext()
8383

84+
_JS_DATE_ISO_REGEX = re.compile(
85+
r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$')
86+
8487
_str_expression_fields = {
8588
'AssignTimestamps': 'timestamp',
8689
'Filter': 'keep',
@@ -227,12 +230,12 @@ def js_to_py(obj):
227230
elif not isinstance(obj, (str, bytes)) and isinstance(obj, Iterable):
228231
return [js_to_py(v) for v in obj]
229232
elif isinstance(obj, str):
230-
try:
231-
if obj.endswith('Z'):
233+
if _JS_DATE_ISO_REGEX.match(obj):
234+
try:
232235
return datetime.datetime.fromisoformat(obj[:-1] + '+00:00')
233-
return datetime.datetime.fromisoformat(obj)
234-
except ValueError:
235-
return obj
236+
except ValueError:
237+
return obj
238+
return obj
236239
else:
237240
return obj
238241

0 commit comments

Comments
 (0)