https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112023-01-02T12:45:34ZRuby Issue Tracking SystemRuby master - Bug #19293: The new Time.new(String) API is nice... but we still need a stricter version of thishttps://bugs.ruby-lang.org/issues/19293?journal_id=1009362023-01-02T12:45:34Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>File</strong> <a href="/attachments/9386">time_benchmark.rb</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/9386/time_benchmark.rb">time_benchmark.rb</a> added</li></ul><p><code>Kernel#Integer</code> may be easier (and probably faster) than the Regexp.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="no">Time</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="n">string</span><span class="p">)</span> <span class="k">unless</span> <span class="no">Integer</span><span class="p">(</span><span class="n">string</span><span class="p">,</span> <span class="ss">exception: </span><span class="kp">false</span><span class="p">)</span>
</code></pre>
<p>Benchmark.</p>
<pre><code>$ ruby time_benchmark.rb
Warming up --------------------------------------
active_model 33.895k i/100ms
time 78.272k i/100ms
Calculating -------------------------------------
active_model 365.327k (± 0.9%) i/s - 1.830M in 5.010500s
time 943.682k (± 1.0%) i/s - 4.775M in 5.060040s
</code></pre>
<p>BTW, <code>fast_string_to_time</code> seems having a bug on the negative offset calculation.</p> Ruby master - Bug #19293: The new Time.new(String) API is nice... but we still need a stricter version of thishttps://bugs.ruby-lang.org/issues/19293?journal_id=1010972023-01-06T15:34:22Zbyroot (Jean Boussier)byroot@ruby-lang.org
<ul></ul><blockquote>
<p>A trustworthy version of ISO8601 parser method perhaps with another name than .new that accepts strict ISO8601-ish String only</p>
</blockquote>
<p>Can we improve <code>Time.iso8601</code>?</p>
<p>Alternatively we could introduce a method based on <a href="https://www.rfc-editor.org/rfc/rfc3339" class="external">https://www.rfc-editor.org/rfc/rfc3339</a>. RFC 3339 is pretty much the date and time part of ISO8601 but publicly documented.</p> Ruby master - Bug #19293: The new Time.new(String) API is nice... but we still need a stricter version of thishttps://bugs.ruby-lang.org/issues/19293?journal_id=1012642023-01-17T12:04:40ZEregon (Benoit Daloze)
<ul></ul><p>I think a new method is cleaner. Or maybe reusing <code>Time.iso8601</code>.</p>
<p>It feels a hack for Time.new two wildly different things based on the number of arguments and as shown here it's ambiguous.<br>
I had the same concerns when Time.new started supporting this, so "told you so" feeling here.</p> Ruby master - Bug #19293: The new Time.new(String) API is nice... but we still need a stricter version of thishttps://bugs.ruby-lang.org/issues/19293?journal_id=1013472023-01-20T06:02:23Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>Discussed at the dev meeting. <a class="user active user-mention" href="https://bugs.ruby-lang.org/users/5">@naruse (Yui NARUSE)</a> said "<code>Time.new("2023")</code> is 1.9.2 feature. We can’t deprecate on 3.2.1. Need to continue the discussion for Ruby 3.3."</p>
<p>BTW Ruby 3.2.0 accidentally allows <code>Time.new("2023-01")</code>, <code>Time.new("2023-01-01")</code>, and <code>Time.new(" \n\n 2023-01-01 00:00:00 \n\n ")</code>. All of these are considered a bug, so will be prohibited (fixed) in Ruby 3.2.1.</p> Ruby master - Bug #19293: The new Time.new(String) API is nice... but we still need a stricter version of thishttps://bugs.ruby-lang.org/issues/19293?journal_id=1036682023-06-22T22:36:04Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Backport</strong> changed from <i>2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN</i> to <i>3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED</i></li></ul><p>mame (Yusuke Endoh) wrote in <a href="#note-4">#note-4</a>:</p>
<blockquote>
<p>BTW Ruby 3.2.0 accidentally allows <code>Time.new("2023-01")</code>, <code>Time.new("2023-01-01")</code>, and <code>Time.new(" \n\n 2023-01-01 00:00:00 \n\n ")</code>. All of these are considered a bug, so will be prohibited (fixed) in Ruby 3.2.1.</p>
</blockquote>
<p>Looks like this wasn't fixed in 3.2.1, 3.2.2, or the master branch. I've submitted a pull request to fix it in the master branch, which could be backported to 3.2.3: <a href="https://github.com/ruby/ruby/pull/7974" class="external">https://github.com/ruby/ruby/pull/7974</a></p> Ruby master - Bug #19293: The new Time.new(String) API is nice... but we still need a stricter version of thishttps://bugs.ruby-lang.org/issues/19293?journal_id=1038492023-07-13T14:44:19Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>Discussed at the dev meeting. The conclusion is:</p>
<ul>
<li>Fix it in master (towards Ruby 3.3)</li>
<li><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/404">@nagachika (Tomoyuki Chikanaga)</a> will decide whether to backport to 3.2.3 or not.</li>
</ul> Ruby master - Bug #19293: The new Time.new(String) API is nice... but we still need a stricter version of thishttps://bugs.ruby-lang.org/issues/19293?journal_id=1038592023-07-13T23:49:49Zjeremyevans (Jeremy Evans)code@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Tighten Time.new(string) parsing Disallow: * Only year-month * Only year-month-day * Preceding ..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/5d4fff845602872eef072e7611558b5f8762efe0">git|5d4fff845602872eef072e7611558b5f8762efe0</a>.</p>
<hr>
<p>Tighten Time.new(string) parsing</p>
<p>Disallow:</p>
<ul>
<li>Only year-month</li>
<li>Only year-month-day</li>
<li>Preceding whitespace</li>
<li>Trailing whitespace</li>
</ul>
<p>Fixes [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: The new Time.new(String) API is nice... but we still need a stricter version of this (Closed)" href="https://bugs.ruby-lang.org/issues/19293">#19293</a>]</p> Ruby master - Bug #19293: The new Time.new(String) API is nice... but we still need a stricter version of thishttps://bugs.ruby-lang.org/issues/19293?journal_id=1039592023-07-23T04:03:40Znagachika (Tomoyuki Chikanaga)nagachika00@gmail.com
<ul><li><strong>Backport</strong> changed from <i>3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED</i> to <i>3.0: DONTNEED, 3.1: DONTNEED, 3.2: DONE</i></li></ul><p>ruby_3_2 0b3ed6043c9d091d499ca1caed604a983c7e285b merged revision(s) 5d4fff845602872eef072e7611558b5f8762efe0.</p>