Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/subscript/fmuobs/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from subscript.fmuobs.util import (
ERT_ALT_DATE_FORMAT,
ERT_DATE_FORMAT,
ERT_ISO_DATE_FORMAT,
uppercase_dictkeys,
)

Expand Down Expand Up @@ -214,12 +215,15 @@ def fix_dtype(value):
return float_value
except ValueError:
try:
return datetime.datetime.strptime(value, ERT_DATE_FORMAT)
return datetime.datetime.strptime(value, ERT_ISO_DATE_FORMAT)
except ValueError:
try:
return datetime.datetime.strptime(value, ERT_ALT_DATE_FORMAT)
return datetime.datetime.strptime(value, ERT_DATE_FORMAT)
except ValueError:
return str(value)
try:
return datetime.datetime.strptime(value, ERT_ALT_DATE_FORMAT)
except ValueError:
return str(value)


def remove_enclosing_curly_braces(string: str) -> str:
Expand Down
1 change: 1 addition & 0 deletions src/subscript/fmuobs/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


ERT_DATE_FORMAT = "%d/%m/%Y"
ERT_ISO_DATE_FORMAT = "%Y-%m-%d"
ERT_ALT_DATE_FORMAT = "%d.%m.%Y" # Not found in doc, but supported by ERT


Expand Down
1 change: 1 addition & 0 deletions tests/test_fmuobs_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def test_filter_comments(string, expected):
("01/01/1900", datetime.datetime(1900, 1, 1)),
("12/24/2020", "12/24/2020"),
("01/12/2020", datetime.datetime(2020, 12, 1)),
("2020-12-01", datetime.datetime(2020, 12, 1)),
],
)
def test_fix_dtype(string, expected):
Expand Down