moment.js and bootstrap-datepicker not respecting a user's timezone
<p>I have a calendar app where a user picks a date for delivery and pickup. The delivery and pickup need to be done in PST, where the drivers are, but the bootstrap-datepicker uses the timezone of the browser. I've added</p>

<pre><code>moment.tz.setDefault("America/Los_Angeles");
</code></pre>

<p>to my <code>application.js</code> file, but the problem is that the date I get back from the datepicker is returned in the timezone of the browser (I've set it to BST for the purposes of testing).</p>

<pre><code>var pickupDate = moment($('#pickup-date').datepicker("getDate"))
=&gt; Thu Jul 07 2016 00:00:00 GMT+0100 (BST)
_d: Wed Jul 06 2016 17:00:00 GMT+0100 (BST)
_i: Thu Jul 07 2016 00:00:00 GMT+0100 (BST)
pickupWindows = (
  windowsByDate[pickupDate.format("YYYY-MM-DD HH:mm:ss ZZ")] || {}
).pickupWindows
</code></pre>

<p>so that when I actually compare the date to the dates in my system, it doesn't work because it's not in PST, as expected. The keys in <code>windowsByDate</code> are indexed by PST, so this code doesn't work and returned <code>undefined</code>.</p>

<p>One hack would be just to re-parse the date as PST, but that seems to be super hacky. Is there a better way to do this? Either force <code>bootstrap-datepicker</code> to assume the dates are in PST, or force the returned date to be in PST?</p>

<p>edit:
Actually, I can't even re-parse the date as PST unless I treat it as a string.</p>

<pre><code>deliveryDateInTimeZone = moment($('#delivery-date').datepicker("getDate"))
deliveryDateInPst = moment(deliveryDateInTimeZone.format("YYYY-MM-DD"), "YYYY-MM-DD").tz("America/Los_Angeles")
</code></pre>

<p>This returns the previous date, because <code>deliveryDateInTimeZone</code> gets set to the current time zone, but when I format the date, it treats it as a PST time and goes back 8 hours.</p>

<p>edit2:
This is my new hack to get the timezone.</p>

<pre><code>deliveryDate = $('#delivery-date').datepicker("getDate")
deliveryDateInPst = moment(deliveryDate.getFullYear() + "-" + (deliveryDate.getMonth() + 1) + "-" + deliveryDate.getDate() + " 00:00:00 " + moment().format("ZZ"))
</code></pre>