summaryrefslogtreecommitdiffstats
path: root/docs/code-quality/lint/linters/eslint-plugin-mozilla/avoid-Date-timing.rst
blob: 378b153f033e9a60842987aa180a5790549eea60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
=================
avoid-Date-timing
=================

Rejects grabbing the current time via Date.now() or new Date() for timing
purposes when the less problematic performance.now() can be used instead.

The performance.now() function returns milliseconds since page load. To
convert that to milliseconds since the epoch, use:

.. code-block:: js

    performance.timing.navigationStart + performance.now()

Often timing relative to the page load is adequate and that conversion may not
be necessary.

Examples of incorrect code for this rule:
-----------------------------------------

.. code-block:: js

    Date.now()

Examples of correct code for this rule:
---------------------------------------

.. code-block:: js

		new Date('2017-07-11');
		performance.now()