title: Stub browser time and time zone with Capybara
body: <p>I have a JavaScript component (e.g. a date picker) that heavily depends on -</p>
  
  <ol>
  <li>The current system time</li>
  <li>The current system time zone</li>
  </ol>
  
  <p>In Ruby and Capybara it's possible to stub any time with the help of libraries such as <a href="https://github.com/travisjeffery/timecop" rel="noreferrer">Timecop</a>. </p>
  
  <p>Is it also possible to stub these values in the headless browser that Capybara controls? </p>
  
  <p>Thanks!</p>
  
  <p>Edit: Here's an example of how Ruby is stubbed but Capybara's browser still uses the system time</p>
  
  <pre><code>before do
    now = Time.zone.parse("Apr 15, 2018 12:00PM")
    Timecop.freeze(now)
  
    visit root_path
  
    binding.pry
  end
  
  &gt; Time.zone.now
  =&gt; Sun, 15 Apr 2018 12:00:00 UTC +00:00
  
  &gt; page.evaluate_script("new Date();")
  =&gt; "2018-03-27T04:15:44Z"
  </code></pre>