ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "mame (Yusuke Endoh)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:110074] [Ruby master Bug#18978] Unexpected behaviour in Time.utc and Time.local when 8 arguments are passed in
Date: Mon, 26 Sep 2022 02:02:34 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-99325.20220926020234.42491@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18978.20220825134122.42491@ruby-lang.org

Issue #18978 has been updated by mame (Yusuke Endoh).


BTW, if you remove the eighth argument, you may also want to remove the following code to handle the argument.

https://github.com/ruby/ruby/blob/d89f8a046753e2f166ee252510aadf1579dbcd63/time.c#L2947-L2955

----------------------------------------
Bug #18978: Unexpected behaviour in Time.utc and Time.local when 8 arguments are passed in
https://bugs.ruby-lang.org/issues/18978#change-99325

* Author: peterzhu2118 (Peter Zhu)
* Status: Open
* Priority: Normal
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
GitHub PR: https://github.com/ruby/ruby/pull/6281

Time.utc and Time.local produce inconsistent and unexpected behaviour when 8 arguments is passed in.

For example, consider the following code:

```ruby
Time.utc(2000, 1, 1, 2, 3, 4, 100)
```

Here's the output on various Ruby implementations:

    MRI: 2000-01-01 02:03:04.0001 UTC
    TruffleRuby: 2000-01-01 02:03:04.0001 UTC
    Opal: 2000-01-01 02:03:04 UTC

If we add an additional argument:

```ruby
Time.utc(2000, 1, 1, 2, 3, 4, 100, 1)
```

The behaviour changes unexpectedly on MRI:

    MRI: 2000-01-01 02:03:04 UTC
    TruffleRuby: 2000-01-01 02:03:04.0001 UTC
    Opal: 2000-01-01 02:03:04 UTC

Notice that the subseconds are lost.

The PR changes it so that 8 arguments is not accepted into the methods (i.e. an ArgumentError is raised when 8 arguments is passed in). Alternatively, we could have similar behaviour as TruffleRuby, where the 8th argument is ignored. However, since the 8th argument is unused, I think it would be less confusing to the user and prevent mistakes if we raised an ArgumentError forbidding it.



-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2022-09-26  2:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-25 13:41 [ruby-core:109692] [Ruby master Bug#18978] Unexpected behaviour in Time.utc and Time.local when 8 arguments are passed in peterzhu2118 (Peter Zhu)
2022-09-26  2:01 ` [ruby-core:110073] " mame (Yusuke Endoh)
2022-09-26  2:02 ` mame (Yusuke Endoh) [this message]
2022-09-26 17:51 ` [ruby-core:110090] " peterzhu2118 (Peter Zhu)
2022-10-06  6:44 ` [ruby-core:110198] " matz (Yukihiro Matsumoto)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-99325.20220926020234.42491@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).