Abstract

This specification defines a JavaScript interface that provides the current time
in sub-millisecond resolution and such that it is not subject to system clock skew or adjustments.

Status of this
document

This section describes the status of this document at the time of
its publication. Other documents may supersede this document. A list of
current W3C publications and the latest revision of this technical report
can be found in the W3C technical reports
index at http://www.w3.org/TR/.

Publication as a Working Draft does not imply endorsement by the
W3C Membership. This is a draft document and may be updated, replaced
or obsoleted by other documents at any time. It is inappropriate to
cite this document as other than work in progress.

1 Introduction

This section is non-normative.

The ECMAScript Language Specification defines the Date object as a time value representing time in milliseconds since 01 January, 1970 UTC. For most purposes, this definition of time is sufficient as
these values represent time to millisecond precision for any instant that is within approximately 285,616 years from
01 January, 1970 UTC. The DOMTimeStamp is defined similarly.

In practice, these definitions of time are subject to both clock skew and adjustment of the system clock. The value of time may not always be monotonically increasing and subsequent values may either decrease
or remain the same.

For example, the following script may log a positive number, negative number, or zero.

For certain tasks this definition of time may not be sufficient as it does not allow for sub-millisecond resolution and is subject to system clock skew. For example,

When attempting to accurately measure the elapsed time of navigating to a Document, fetching of resources or execution of script, a monotonically increasing clock
with sub-millisecond resolution is desired.

When calculating the animation state from script, developers will need to accurately know the amount of time that has elapsed in the animation in order to properly update the
next scene of the animation.

When calculating the frame rate of a script based animation, developers will need sub-millisecond resolution in order to determine if an animation is drawing at 60 FPS.
Without sub-millisecond resolution, a developer can only determine if an animation is drawing at 58.8 FPS or 62.5 FPS.

In order to cue audio to a specific point in an animation or ensure that the audio is synchronized with the animation,
developers will need to accurately know the amount of time elapsed in the animation and audio.

This specification does not propose changing the behavior of Date.now() as it is genuinely useful in determining the current value of the calendar time and has a long history of
usage. The DOMHighResTimeStamp type and the now method of the
Performance interface resolve the issues summarized in this section by providing a monotonically increasing time value in sub-millisecond resolution.

2 Conformance
requirements

All diagrams, examples, and notes in this specification are non-normative,
as are all sections explicitly marked non-normative. Everything else in this
specification is normative.

The key words "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT",
"RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document
are to be interpreted as described in RFC 2119.
For readability, these words do not appear in all uppercase letters in this specification.

Some conformance requirements are phrased as requirements on attributes,
methods or objects. Such requirements are to be interpreted as requirements
on user agents.

The IDL fragments in this specification must be interpreted as
required for conforming IDL fragments, as described in the Web IDL
specification. [Web IDL]

3 Terminology

The construction "a Foo object", where Foo is actually an interface, is sometimes used instead of
the more accurate "an object implementing the interface Foo".

The term "JavaScript" is used to refer to
ECMA-262,
rather than the official term ECMAScript, since the term JavaScript is more widely known.

4 High Resolution Time

4.1 Introduction

This section is non-normative.

This specification defines an interface that provides the current time
in sub-millisecond resolution and such that it is not subject to system clock skew or adjustments.

4.2 The DOMHighResTimeStamp Type

The DOMHighResTimeStamp
type is used to store a time value measured relative to the
start of navigation of the document, or a time value that
represents a duration between
two DOMHighResTimeStamps.

A DOMHighResTimeStamp SHOULD represent a number of milliseconds accurate to a thousandth of a millisecond.

Note

If the User Agent is unable to provide a time value accurate to a thousandth of a millisecond due to hardware or software constraints, the User Agent
can represent a DOMHighResTimeStamp as a number of milliseconds accurate to a millisecond.

4.4 Monotonic Clock

The time values returned when calling the now method MUST be monotonically increasing and not subject to system clock
adjustments or system clock skew. The difference between any two chronologically recorded time values returned from the
now method MUST never be negative.

4.5 Privacy and Security

Statistical fingerprinting is a privacy concern where a malicious web site may determine whether a user has visited a
third-party web site by measuring the timing of cache hits and misses of resources in the third-party web site.
Though the now method of the Performance interface
returns time data to a greater accuracy than before, it does not make this privacy concern significantly worse than it was already.

Navigation Timing, Zhiheng Wang, Editor. World Wide Web Consortium, December 2012. This version of the Navigation Timing Recommendation is available from http://www.w3.org/TR/2012/REC-navigation-timing-20121217/. The latest version of Navigation Timing is available at http://www.w3.org/TR/navigation-timing/.

[Web IDL]

Web
IDL, Cameron McCormack, Editor. World Wide Web
Consortium, April 2012. This version of the Web IDL
specification is available from
http://www.w3.org/TR/2012/CR-WebIDL-20120419/.
The latest version of Web
IDL is available at http://www.w3.org/TR/WebIDL/.

Page Visibility, Jatinder Mann and Arvind Jain, Editors. World Wide Web Consortium, July 2012.
This version of the Page Visibility specification is available from http://www.w3.org/TR/2012/CR-page-visibility-20120726/. The latest version of Page Visibility is available at http://www.w3.org/TR/page-visibility/.

Acknowledgements

I would like to sincerely thank Karen Anderson, Nat Duca, Tony Gentilcore, Arvind Jain, James Robinson, James Simonsen, and Jason Weber
to acknowledge their contributions to this work.