Skip to content

Validate inferred time zone offsets - #270

Merged
kelly-nelson merged 13 commits into
ADAPT:developfrom
ericpohl:develop
Apr 22, 2026
Merged

Validate inferred time zone offsets #270
kelly-nelson merged 13 commits into
ADAPT:developfrom
ericpohl:develop

Conversation

@ericpohl

Copy link
Copy Markdown
Contributor

There are two places in the code where we infer the timezone offset vs. UTC by comparing DateTime values - a UTC value in a SpatialRecord, presumably from the GPS, and a local value from the monitor. We then use this timezone offset to compute DateTimeOffset values in SpatialRecordMapper.ToUtc().

We were seeing data come in from the field in which the inferred timezone offset was 19 hours, which raised an ArgumentOutOfRangeException in the DateTimeOffset constructor:

{System.ArgumentOutOfRangeException: Offset must be within plus or minus 14 hours. (Parameter 'offset')
   at System.DateTimeOffset.ValidateOffset(TimeSpan offset)
   at System.DateTimeOffset..ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second, Int32 millisecond, TimeSpan offset)
   at AgGateway.ADAPT.ISOv4Plugin.Mappers.SpatialRecordMapper.ToUtc(DateTime dateTime, Nullable`1 timezoneOffset)
   at AgGateway.ADAPT.ISOv4Plugin.Mappers.SpatialRecordMapper.GovernsTimestamp(ISOProductAllocation p, SpatialRecord spatialRecord)
   at AgGateway.ADAPT.ISOv4Plugin.Mappers.SpatialRecordMapper.<>c__DisplayClass11_0.<SetNumericMeterValue>b__1(ISOProductAllocation p)
   at AgGateway.ADAPT.ISOv4Plugin.Mappers.SpatialRecordMapper.SetNumericMeterValue(ISOSpatialRow isoSpatialRow, NumericWorkingData meter, SpatialRecord spatialRecord, Dictionary`2 productAllocations)
   at AgGateway.ADAPT.ISOv4Plugin.Mappers.SpatialRecordMapper.Map(ISOSpatialRow isoSpatialRow, List`1 meters, Dictionary`2 productAllocations)
   at AgGateway.ADAPT.ISOv4Plugin.Mappers.SpatialRecordMapper.<>c__DisplayClass8_0.<Map>b__0(ISOSpatialRow r)

It appears that the monitor had the date set one day ahead (24 hours ahead minus 5 hour timezone offset = 19 hours). There is no reliable way to fix this data that I am aware of, so instead of throwing away the entire dataset, simply null out the timezone offset, record an error, and proceed as best we can.

An additional change is to add the .vscode subdirectory to .gitignore, as this contains user-specific data for Visual Studio Code.

@kelly-nelson

Copy link
Copy Markdown
Contributor

Looks good to me. @strhea ?

@strhea

strhea commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Agreed.

@kelly-nelson
kelly-nelson merged commit 7405b4d into ADAPT:develop Apr 22, 2026
1 check passed
kelly-nelson added a commit that referenced this pull request Jul 22, 2026
* Performance refactorings (#267)

* Construct DateTime objects with Local DateTimeKind

* Consolidate "first day of 1980" fields

* More messing with timezones

* Cleanup

* Performance refactorings

* .gitignore JetBrains

* Renaming

---------

Co-authored-by: Eric Pohl <eric.pohl@corteva.com>

* ReadImplementGeometryValues: prefer the most common value for each DLV (#268)

* Change ReadImplementGeometryValues to prefer the most common value for each dlv rather than the farthest from zero

Signed-off-by: Andrew Vardeman <avardeman@agleader.com>

* Remove debugging code

Signed-off-by: Andrew Vardeman <avardeman@agleader.com>

---------

Signed-off-by: Andrew Vardeman <avardeman@agleader.com>

* Validate inferred time zone offsets  (#270)

* Construct DateTime objects with Local DateTimeKind

* Consolidate "first day of 1980" fields

* More messing with timezones

* Cleanup

* Performance refactorings

* .gitignore JetBrains

* Renaming

* Remove .vscode files from tracking

* Validate inferred timezone offsets

---------

Co-authored-by: Eric Pohl <eric.pohl@corteva.com>

* Make GetOperationTypeFromLoggingDevices respect just the device under consideration rather than all devices for a time log.

Signed-off-by: Andrew Vardeman <avardeman@agleader.com>

---------

Signed-off-by: Andrew Vardeman <avardeman@agleader.com>
Co-authored-by: Eric Pohl <31418444+ericpohl@users.noreply.github.com>
Co-authored-by: Eric Pohl <eric.pohl@corteva.com>
Co-authored-by: Andrew Vardeman <andrew.vardeman.dev@gmail.com>
Co-authored-by: Stuart Rhea <stuart.rhea@live.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants