Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not only is it legal, is it <em>required</em>.</p> <p>The behaviour is officially defined in the <a href="http://ecma-international.org/ecma-262/5.1/#sec-15.9.5.34" rel="nofollow">ECMAScript specification</a>, section 15.9.5.34:</p> <blockquote> <p><strong>Date.prototype.setHours (hour [, min [, sec [, ms ] ] ] )</strong></p> <p>If <em>min</em> is not specified, this behaves as if <em>min</em> were specified with the value <strong><code>getMinutes()</code></strong>.</p> <p>If <em>sec</em> is not specified, this behaves as if <em>sec</em> were specified with the value <strong><code>getSeconds()</code></strong>.</p> <p>If <em>ms</em> is not specified, this behaves as if <em>ms</em> were specified with the value <strong><code>getMilliseconds()</code></strong>.</p> <ol> <li>Let <em>t</em> be the result of LocalTime(this time value).</li> <li>Let <em>h</em> be ToNumber(<em>hour</em>).</li> <li>If <em>min</em> is not specified, then let <em>m</em> be MinFromTime(<em>t</em>); otherwise, let <em>m</em> be ToNumber(<em>min</em>).</li> <li>If <em>sec</em> is not specified, then let <em>s</em> be SecFromTime(<em>t</em>); otherwise, let <em>s</em> be ToNumber(<em>sec</em>).</li> <li>If <em>ms</em> is not specified, then let <em>milli</em> be msFromTime(<em>t</em>); otherwise, let <em>milli</em> be ToNumber(<em>ms</em>).</li> <li>Let <em>date</em> be MakeDate(Day(<em>t</em>), MakeTime(<em>h</em>, <em>m</em>, <em>s</em>, <em>milli</em>)).</li> <li>Let <em>u</em> be TimeClip(UTC(<em>date</em>)).</li> <li>Set the [[PrimitiveValue]] internal property of this Date object to <em>u</em>.</li> <li>Return <em>u</em></li> </ol> </blockquote> <p>And the specification for <code>MakeTime</code>, used in step 6, ultimately calculates a millisecond offset by multiplying the various parts together. There are no preconditions for bounds on the arguments (other than that they are finite), so a negative number of hours is legal, and will result in a negative result.</p> <p>Thus the overall result, that is midnight + (-1 hours), does need to be 23:00 on the previous day to conform with the spec.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload