Skip to content

Commit 5e4b5a8

Browse files
rettichschnidiphanak-sap
authored andcommitted
model: adjust default Edm.DateTime value (#79)
This makes it easier, more likely, to spot dates fixed-up by pyodata. The new value aligns with Edm.DateTimeOffset.
1 parent db2c77d commit 5e4b5a8

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
- Fix Increased robustness when schema with empty properties is returned
1111
- Use valid default value for Edm.DateTimeOffset - Reto Schneider
1212

13+
### Changed
14+
- Adjusted Edm.DateTime default value to January 1, 1753 A.D - Reto Schneider
15+
1316
## [1.8.0]
1417

1518
### Fixed

pyodata/v2/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def _build_types():
186186
Types.register_type(Typ('Edm.Binary', 'binary\'\'', EdmBinaryTypTraits('(?:binary|X)')))
187187
Types.register_type(Typ('Edm.Boolean', 'false', EdmBooleanTypTraits()))
188188
Types.register_type(Typ('Edm.Byte', '0'))
189-
Types.register_type(Typ('Edm.DateTime', 'datetime\'2000-01-01T00:00\'', EdmDateTimeTypTraits()))
189+
Types.register_type(Typ('Edm.DateTime', 'datetime\'1753-01-01T00:00\'', EdmDateTimeTypTraits()))
190190
Types.register_type(Typ('Edm.Decimal', '0.0M'))
191191
Types.register_type(Typ('Edm.Double', '0.0d', EdmFPNumTypTraits.edm_double()))
192192
Types.register_type(Typ('Edm.Single', '0.0f', EdmFPNumTypTraits.edm_single()))

tests/test_service_v2.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,6 +2345,28 @@ def test_create_entity_with_naive_datetime(service):
23452345
assert str(e_info.value).startswith('Edm.DateTime accepts only UTC')
23462346

23472347

2348+
@responses.activate
2349+
def test_null_datetime(service):
2350+
"""Test default value of DateTime. Default value gets inserted when a property is null"""
2351+
2352+
responses.add(
2353+
responses.GET,
2354+
f"{service.url}/TemperatureMeasurements",
2355+
headers={'Content-type': 'application/json'},
2356+
json={'d': {
2357+
'results': [
2358+
{
2359+
'Date': None,
2360+
}
2361+
]
2362+
}},
2363+
status=200)
2364+
2365+
result = service.entity_sets.TemperatureMeasurements.get_entities().execute()
2366+
2367+
assert result[0].Date == datetime.datetime(1753, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc)
2368+
2369+
23482370
@responses.activate
23492371
def test_parsing_of_datetime_before_unix_time(service):
23502372
"""Test DateTime handling of time before 1970"""

0 commit comments

Comments
 (0)