title: Using sinon to mock a date object
body: <p>Here is my code:</p>
  
  <pre><code>var startTime = new Date(startDateTime).toLocaleTimeString("en-US", options);
  </code></pre>
  
  <p>I need to get that <code>startTime</code> in my unit test. From knowing unit testing in a java perspective, I would approach this problem as <em>How can I mock the new date constructor?</em> and then <em>How can I mock the toLocaleTimeString function call?</em>. However, I'm not sure that that's the way to approach this problem in javascript.</p>
  
  <p>I've tried several things including sinon's useFakeTimers, but I don't think that's relevant as I'm not actually interested in the passage of time.</p>
  
  <p>Here is my test code right now gleamed from lots of googling with zero context of how sinon works:</p>
  
  <pre><code>var whatever = sinon.spy(global, 'Date');
  sinon.stub(whatever, 'toLocaleTimeString').yields('7:00 PM');
  </code></pre>
  
  <p>However, this gives the error "Attempted to wrap undefined property toLocaleTimeString as function".</p>
  
  <p>Please help me understand the logic behind how I am meant to stub out this sort of functionality and how I do so.</p>