Commit b0dfe0e8 authored by Amir Golparvar's avatar Amir Golparvar
Browse files

Bugfixing datetime to accept strings with white spaces and timezone info

parent a89f81b3
Pipeline #134821 passed with stages
in 46 minutes and 54 seconds
......@@ -790,6 +790,10 @@ class _File(DataType):
class _Datetime(DataType):
def _parse(self, datetime_str: str) -> datetime:
# removing trailing spaces and replacing the potential white space between date and time with char 'T'
if datetime_str[0].isdigit():
datetime_str = datetime_str.strip().replace(' ', 'T')
try:
return aniso8601.parse_datetime(datetime_str)
except ValueError:
......
......@@ -72,6 +72,7 @@ def test_basic_types(def_type, value):
@pytest.mark.parametrize('def_type, orig_value, normalized_value', [
pytest.param(Unit, 'm*m/s', units.parse_units('m*m/s'), id='Unit'),
pytest.param(Datetime, '1970-01-01 01:00:00', None, id='Datetime-str'),
pytest.param(Datetime, '1970-01-01 01:00+01', None, id='Datetime-str-tz'),
pytest.param(Datetime, '1970-01-01 01:00:00.0000', None, id='Datetime-str-ms'),
pytest.param(Datetime, 'Wed, 01 Jan 1970 00:00:00 -0100', None, id='Datetime-rfc822'),
pytest.param(Datetime, '1970-01-01T00:00:00Z', None, id='Datetime-aniso861-time'),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment