Skip to content

Commit b485f26

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 w3c#463.
1 parent d41fea3 commit b485f26

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

index.bs

Lines changed: 25 additions & 10 deletions
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=].
@@ -1148,11 +1145,14 @@ with the internal slots described in the following table:
11481145

11491146
### Sensor.timestamp ### {#sensor-timestamp}
11501147

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

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

11571157
### Sensor.start() ### {#sensor-start}
11581158

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

0 commit comments

Comments
 (0)