<p dir="auto">The test suit currently fails if your development environment (e.g. your own laptop) is set to a timezone outside of the UK. I encountered this earlier this year, at the Karlsruhe Hack Weekend, but I'm surprised more people haven't complained about it! The failing test is:</p>
<pre class="notranslate"><code class="notranslate">Failure:
ApplicationHelperTest#test_friendly_date [/home/andy/src/openstreetmap-website/test/helpers/application_helper_test.rb:62]:
Expected /^<span title=" *5 March 2014 at 18:58">.*<\/span>$/ to match "<span title=\" 5 March 2014 at 17:58\">over 9 years</span>".
</code></pre>
<p dir="auto">This is because that test uses <code class="notranslate">Time.new(...).utc</code>, which is not the same thing as <code class="notranslate">Time.utc(...)</code>.</p>
<p dir="auto">But why does it work - all year round - in the UK?</p>
<p dir="auto"><code class="notranslate">Time.new</code> takes an optional list of year, month, day etc (defaults to midnight first of January) and an implicit "in the current system timezone". If you ask for a date in the winter, it will use the winter equivalent of your current timezone. For example:</p>
<div class="highlight highlight-source-ruby" dir="auto"><pre class="notranslate">>> <span class="pl-v">Time</span><span class="pl-kos">.</span><span class="pl-en">now</span><span class="pl-kos">.</span><span class="pl-en">zone</span>
<span class="pl-c1">=></span> <span class="pl-s">"BST"</span><span class="pl-en"></span>
>> <span class="pl-v">Time</span><span class="pl-kos">.</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-c1">2020</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">zone</span>
<span class="pl-c1">=></span> <span class="pl-s">"GMT"</span></pre></div>
<p dir="auto">Therefore, there is no problem in either summer or winter for the UK, both approaches give the same time. For example:</p>
<div class="highlight highlight-source-ruby" dir="auto"><pre class="notranslate">>> <span class="pl-v">Time</span><span class="pl-kos">.</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-c1">2020</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">utc</span>
<span class="pl-c1">=></span> <span class="pl-c1">2020</span>-<span class="pl-c1">01</span>-<span class="pl-c1">01</span> <span class="pl-c1">00</span><span class="pl-pds">:00</span><span class="pl-pds">:00</span> <span class="pl-c1">UTC</span><span class="pl-en"></span>
>> <span class="pl-v">Time</span><span class="pl-kos">.</span><span class="pl-en">utc</span><span class="pl-kos">(</span><span class="pl-c1">2020</span><span class="pl-kos">)</span>
<span class="pl-c1">=></span> <span class="pl-c1">2020</span>-<span class="pl-c1">01</span>-<span class="pl-c1">01</span> <span class="pl-c1">00</span><span class="pl-pds">:00</span><span class="pl-pds">:00</span> <span class="pl-c1">UTC</span></pre></div>
<p dir="auto">Imagine the first line above says <code class="notranslate">Time.new(2020, 'GMT').utc</code> i.e. midnight GMT. Then convert that to UTC, which is the same time, also midnight.</p>
<p dir="auto">However, if you switch your laptop to a different timezone:</p>
<div class="highlight highlight-source-ruby" dir="auto"><pre class="notranslate">>> <span class="pl-v">Time</span><span class="pl-kos">.</span><span class="pl-en">now</span><span class="pl-kos">.</span><span class="pl-en">zone</span>
<span class="pl-c1">=></span> <span class="pl-s">"CEST"</span><span class="pl-en"></span>
>> <span class="pl-v">Time</span><span class="pl-kos">.</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-c1">2020</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">zone</span>
<span class="pl-c1">=></span> <span class="pl-s">"CET"</span><span class="pl-en"></span>
>> <span class="pl-v">Time</span><span class="pl-kos">.</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-c1">2020</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">utc</span>
<span class="pl-c1">=></span> <span class="pl-c1">2019</span>-<span class="pl-c1">12</span>-<span class="pl-c1">31</span> <span class="pl-c1">23</span><span class="pl-pds">:00</span><span class="pl-pds">:00</span> <span class="pl-c1">UTC</span><span class="pl-en"></span>
>> <span class="pl-v">Time</span><span class="pl-kos">.</span><span class="pl-en">utc</span><span class="pl-kos">(</span><span class="pl-c1">2020</span><span class="pl-kos">)</span>
<span class="pl-c1">=></span> <span class="pl-c1">2020</span>-<span class="pl-c1">01</span>-<span class="pl-c1">01</span> <span class="pl-c1">00</span><span class="pl-pds">:00</span><span class="pl-pds">:00</span> <span class="pl-c1">UTC</span></pre></div>
<p dir="auto">The third line can now be considered as <code class="notranslate">Time.new(2020, CET).utc</code> i.e. midnight 1st January in CET, which is then converted to 23:00 the previous day in UTC.</p>
<p dir="auto">This test previously used <code class="notranslate">Time.new(2014, 3, 5, 18, 58, 23).utc</code> which we can see will be created in the local timezone at 18:58 and then converted to some other time in UTC, depending on your timezone offset from UTC e.g. it might be 17:58 UTC if you are in CE(S)T.</p>
<p dir="auto">We already used two other forms of date expression in the tests, both <code class="notranslate">Time.new(..., "+00:00")</code> and also <code class="notranslate">Time.utc(...)</code>, neither of which have this problem. I've standardized on <code class="notranslate">Time.utc(...)</code> in this PR because it allows the minutes, seconds etc to be omitted when they are unimportant, for better readability.</p>

<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/openstreetmap/openstreetmap-website/pull/4063'>https://github.com/openstreetmap/openstreetmap-website/pull/4063</a></p>

<h4>Commit Summary</h4>
<ul>
  <li><a href="https://github.com/openstreetmap/openstreetmap-website/pull/4063/commits/2f7642aa035a82576ee4bb69c284005d731c081e" class="commit-link">2f7642a</a>  Fix test to work in non-UK timezones</li>
  <li><a href="https://github.com/openstreetmap/openstreetmap-website/pull/4063/commits/73e0c4ed2126ee378a912c6fab654dd8e0173c69" class="commit-link">73e0c4e</a>  Use Time.utc for consistency with other tests</li>
</ul>

<h4 style="display: inline-block">File Changes </h4> <p style="display: inline-block">(<a href="https://github.com/openstreetmap/openstreetmap-website/pull/4063/files">2 files</a>)</p>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4063/files#diff-59e3c27d200847ec53b2bbfa85d7d93e45d2f4b0d40237eaf81a84085e29989c">test/helpers/application_helper_test.rb</a>
    (2)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4063/files#diff-77adf9b5a9670ed38070915c07a4ff7bfde667deaee2327f0055194e5fd71b74">test/helpers/note_helper_test.rb</a>
    (4)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/openstreetmap/openstreetmap-website/pull/4063.patch'>https://github.com/openstreetmap/openstreetmap-website/pull/4063.patch</a></li>
  <li><a href='https://github.com/openstreetmap/openstreetmap-website/pull/4063.diff'>https://github.com/openstreetmap/openstreetmap-website/pull/4063.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/4063">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLNVR5UP3LQCEAIYYCDXLHNUBANCNFSM6AAAAAAZGSU2LA">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLLBUG6WJFLZ7EDSO6LXLHNUBA5CNFSM6AAAAAAZGSU2LCWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHGRPIQDI.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/4063</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/4063",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/4063",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>