Commit 380abede authored by CharlieC's avatar CharlieC
Browse files

Handle OverflowError for date.

Resolves #1670

--HG--
branch : 3.0
parent 0239cda4b885
......@@ -206,8 +206,8 @@ class WorkSheetParser(object):
value = from_excel(
value, self.epoch, timedelta=style_id in self.timedelta_formats
)
except ValueError:
msg = """Cell {0} is marked as a date but the serial value {1} is outside the limits for dates. The cell will be treated as an error.""".format(coordinate, value)
except (OverflowError, ValueError):
msg = f"""Cell {coordinate} is marked as a date but the serial value {value} is outside the limits for dates. The cell will be treated as an error."""
warn(msg)
data_type = "e"
value = "#VALUE!"
......
......@@ -320,6 +320,24 @@ class TestWorksheetParser:
assert cell == {'column': 1, 'data_type': 'd', 'row': 1,
'style_id':29, 'value':datetime.datetime(2016, 10, 3, 0, 0)}
@pytest.mark.parametrize("value", [
-693595,
2958466,
]
)
def test_out_of_range_datetime(self, WorkSheetParser, recwarn, value):
parser = WorkSheetParser
src = f"""
<c r="A1" t="n" s="29" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<v>{value}</v>
</c>
"""
element = fromstring(src)
parser.parse_cell(element)
w = recwarn.pop()
assert issubclass(w.category, UserWarning)
def test_string(self, WorkSheetParser):
parser = WorkSheetParser
......
Markdown is supported
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