Skip to content

Commit 814c47b

Browse files
author
Raphael Kubo da Costa
committed
Tighten the Sensor.timestamp and latest reading["timestamp"] definitions
latest reading["timestamp"] was not defined strictly enough: the definition mentioned "the time origin", which is a concept that only exists related to a given environment settings object. We now have it be an "unsafe current time" as defined by the High Resolution Time specification, and its value is always set using the same monotonic clock -- if we get a timestamp directly from a device sensor (e.g. a WinRT timestamp relative to the Windows epoch) it needs to be translated into a timestamp that makes sense with the monotonic clock. Finally, Sensor.timestamp no longer just returns latest reading["timestamp"] and instead ensures that whatever "unsafe current time" the latter returns is coarsened and converted to a value relative to its relevant time origin. Related to #463.
1 parent f0dca6f commit 814c47b

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

index.bs

+25-10
Original file line numberDiff line numberDiff line change
@@ -845,13 +845,10 @@ the [=sensor reading=] as arguments.
845845

846846
The [=latest reading=] [=ordered map|map=] contains an [=map/entry=] whose [=map/key=] is
847847
"timestamp" and whose [=map/value=] is a high resolution timestamp that estimates the
848-
[=reading timestamp=] expressed in milliseconds since the [=time origin=].
848+
[=reading timestamp=] expressed in milliseconds as an [=monotonic clock/unsafe current time=].
849849

850-
Note: The accuracy of the [=reading timestamp=] estimate depends on the underlying
851-
platform interfaces that expose it.
852-
853-
The [=latest reading=]["timestamp"] is initially set to null,
854-
unless the [=latest reading=] [=ordered map|map=] caches a previous [=sensor readings|reading=].
850+
[=Latest reading=]["timestamp"] is initially set to null, unless the [=latest reading=] [=map=]
851+
caches a previous [=sensor readings|reading=].
855852

856853
The other [=map/entries=] of the [=latest reading=] [=ordered map|map=]
857854
hold the values of the different quantities measured by the [=platform sensor=].
@@ -1146,11 +1143,14 @@ with the internal slots described in the following table:
11461143

11471144
### Sensor.timestamp ### {#sensor-timestamp}
11481145

1149-
The {{Sensor/timestamp!!attribute}} getter steps are to return
1150-
the result of invoking [=get value from latest reading=] with [=this=]
1151-
and "timestamp" as arguments.
1146+
<div algorithm="sensor timestamp">
1147+
The {{Sensor/timestamp}} getter steps are:
11521148

1153-
It represents a [=reading timestamp=].
1149+
1. Let |global| be [=this=]'s [=relevant global object=].
1150+
2. Let |unsafeTimestamp| be the result of invoking [=get value from latest reading=] with
1151+
[=this=] and "timestamp" as arguments.
1152+
3. Return [=relative high resolution time=] with |unsafeTimestamp| and |global|.
1153+
</div>
11541154

11551155
### Sensor.start() ### {#sensor-start}
11561156

@@ -1437,6 +1437,21 @@ to {{SensorErrorEventInit}}.
14371437
1. Let |result| be the result of invoking |type|'s [=threshold check algorithm=]
14381438
with |reading| and |sensor|'s [=latest reading=].
14391439
1. If |result| is false, then abort these steps.
1440+
1. If |reading|["timestamp"] [=map/exists=]:
1441+
<!-- The language below is similar to what is found in
1442+
https://w3c.github.io/hr-time/#timeorigin-attribute -->
1443+
1. Set |reading|["timestamp"] to the result of converting its current value in an
1444+
[=implementation-defined=] way to an [=monotonic clock/unsafe current time=] using the
1445+
same [=monotonic clock=] that is shared by [=time origins=].
1446+
1447+
Note: The goal of this step is to ensure that a timestamp that may have been relative to
1448+
a different time origin is converted to a value that can be used in computations with
1449+
the same [=monotonic clock=] used by the operations described in [[HR-TIME]].
1450+
1. Otherwise, [=map/set=] |reading|["timestamp"] to the [=unsafe shared current time=].
1451+
1452+
Note: In neither case is an [=monotonic clock/unsafe current time=] ever exposed to script.
1453+
{{Sensor/timestamp|Sensor.timestamp}} always returns a [=moment/coarsened moment=] relative
1454+
to a [=time origin=].
14401455
1. [=map/For each=] |key| → <var ignore>value</var> of [=latest reading=].
14411456
1. [=map/Set=] [=latest reading=][|key|] to the corresponding
14421457
value of |reading|.

0 commit comments

Comments
 (0)