RalphTro / epcis-event-hash-generator

ALGORITHM and SOFTWARE PROTOTYPE to uniquely identify/validate the integrity of any EPCIS event through a common, syntax-agnostic approach based on hashing. Takes an EPCIS Document (formatted in either XML or JSON-LD) and returns the corresponding hash value(s).
MIT License
8 stars 4 forks source link

Rounding up/down timestamps with more than 3 decimal places #84

Closed RalphTro closed 1 year ago

RalphTro commented 1 year ago

Dear all,

In one of our last EPCIS calls, we discussed how to handle dateTimeStamps with decimal places that go beyond three places.

Mark came up with the following refinement of rule no. 9:

All timestamps SHALL be expressed with millisecond precision. If an EPCIS event lacks the latter, the millisecond field SHALL be zero-filled with ‘000’ (e.g., YYYY-MM-DDTHH:MM:SS.000Z). xsd:dateTimeStamp permits an unlimited number of decimal places to be expressed. If more than 3 decimal places are expressed, the 3rd decimal place SHALL be rounded up if the 4th decimal place is a digit in the range 5-9. For example, an xsd:dateTimeStamp value of 2023-01-18T11:04:03.1415Z would appear in the pre-hash string as 2023-01-18T11:04:03.142Z .

Now, I tested this behavior with our current master branch (thereby passing the algorithm an EPCIS event document having more granular eventTime values):

{
  "@context": [
    "https://ref.gs1.org/standards/epcis/2.0.0/epcis-context.jsonld"
  ],
  "type": "EPCISDocument",
  "schemaVersion": "2.0",
  "creationDate": "2023-02-02T11:05:00.0Z",
  "epcisBody": {
    "eventList": [
      {
        "type": "ObjectEvent",
        "eventTime": "2023-02-02T11:04:03.1415Z",
        "eventTimeZoneOffset": "+01:00",
        "epcList": [
          "https://id.gs1.de/00/040123451111111110"
        ],
        "action": "OBSERVE",
        "bizStep": "shipping",
        "disposition": "in_transit",
        "readPoint": {
          "id": "https://id.gs1.de/414/4012345000115"
        }
      },
{
        "type": "ObjectEvent",
        "eventTime": "2023-02-02T11:04:03.1414Z",
        "eventTimeZoneOffset": "+01:00",
        "epcList": [
          "https://id.gs1.de/00/040123451111111110"
        ],
        "action": "OBSERVE",
        "bizStep": "transporting",
        "readPoint": {
          "id": "geo:50.947573340894124,6.922120147375441"
        }
      }
    ]
  }
}

The pre-hash strings that are returned are as follows:

eventType=ObjectEvent
eventTime=2023-02-02T11:04:03.141Z
eventTimeZoneOffset=+01:00
epcListepc=https://id.gs1.org/00/040123451111111110
action=OBSERVE
bizStep=https://ref.gs1.org/cbv/BizStep-shipping
disposition=https://ref.gs1.org/cbv/Disp-in_transit
readPointid=https://id.gs1.org/414/4012345000115

eventType=ObjectEvent
eventTime=2023-02-02T11:04:03.141Z
eventTimeZoneOffset=+01:00
epcListepc=https://id.gs1.org/00/040123451111111110
action=OBSERVE
bizStep=https://ref.gs1.org/cbv/BizStep-transporting
readPointid=geo:50.947573340894124,6.922120147375441

Therefore, it seems that all timestamps are currently just truncated, not rounded. This should be adjusted.

Anyone willing to take care of this subject?

Kind regards, @RalphTro

RalphTro commented 1 year ago

Many thanks in advance for looking into this, @dakbhavesh!