w3c / sensors

Generic Sensor API
https://www.w3.org/TR/generic-sensor/
Other
127 stars 59 forks source link

Comparison between seconds and milliseconds in "Report latest reading updated"? #441

Open rakuco opened 2 years ago

rakuco commented 2 years ago

https://w3c.github.io/sensors/#report-latest-reading-updated has:

  • Let reportingInterval be the result of 1 / reportingFrequency.
  • Let timestampDelta be the result of latest reading["timestamp"] - lastReportedTimestamp.
  • If timestampDelta is greater than or equal to reportingInterval
    • [...]

reportingFrequency is measured in Hz, so reportingInterval is measured in seconds. latest reading["timestamp"] and lastReportedTimestamp, on the other hand, are high resolution timestamps measured in milliseconds.

A timestampDelta of 2 means a different of two milliseconds, while a sampling frequency of 1Hz means reportingInterval is 1 and the check above will be true even though it should not.

reillyeon commented 2 years ago

Good catch. I assume this bug doesn't exist in the implementation thanks to using safer time types in actual code.