99 PolicyIgnore , Config , PolicyFatal , NullType , NullAssociation , current_timezone , StructType
1010from pyodata .exceptions import PyODataException , PyODataModelError , PyODataParserError
1111from tests .conftest import assert_logging_policy
12+ import pyodata .v2 .model
1213
1314
1415def test_edmx (schema ):
@@ -537,10 +538,20 @@ def test_traits_datetime():
537538 assert testdate .microsecond == 0
538539 assert testdate .tzinfo == current_timezone ()
539540
541+ # parsing below lowest value with workaround
542+ pyodata .v2 .model .FIX_SCREWED_UP_MINIMAL_DATETIME_VALUE = True
543+ testdate = typ .traits .from_json ("/Date(-62135596800001)/" )
544+ assert testdate .year == 1
545+ assert testdate .month == 1
546+ assert testdate .day == 1
547+ assert testdate .tzinfo == current_timezone ()
548+
540549 # parsing the lowest value
541- with pytest .raises (OverflowError ):
550+ pyodata .v2 .model .FIX_SCREWED_UP_MINIMAL_DATETIME_VALUE = False
551+ with pytest .raises (PyODataModelError ) as e_info :
542552 typ .traits .from_json ("/Date(-62135596800001)/" )
543-
553+ assert str (e_info .value ).startswith ('Cannot decode datetime from value -62135596800001.' )
554+
544555 testdate = typ .traits .from_json ("/Date(-62135596800000)/" )
545556 assert testdate .year == 1
546557 assert testdate .month == 1
@@ -551,9 +562,19 @@ def test_traits_datetime():
551562 assert testdate .microsecond == 0
552563 assert testdate .tzinfo == current_timezone ()
553564
565+ # parsing above highest value with workaround
566+ pyodata .v2 .model .FIX_SCREWED_UP_MAXIMUM_DATETIME_VALUE = True
567+ testdate = typ .traits .from_json ("/Date(253402300800000)/" )
568+ assert testdate .year == 9999
569+ assert testdate .month == 12
570+ assert testdate .day == 31
571+ assert testdate .tzinfo == current_timezone ()
572+
554573 # parsing the highest value
555- with pytest .raises (OverflowError ):
574+ pyodata .v2 .model .FIX_SCREWED_UP_MAXIMUM_DATETIME_VALUE = False
575+ with pytest .raises (PyODataModelError ) as e_info :
556576 typ .traits .from_json ("/Date(253402300800000)/" )
577+ assert str (e_info .value ).startswith ('Cannot decode datetime from value 253402300800000.' )
557578
558579 testdate = typ .traits .from_json ("/Date(253402300799999)/" )
559580 assert testdate .year == 9999
0 commit comments