[ruby-core:109692] [Ruby master Bug#18978] Unexpected behaviour in Time.utc and Time.local when 8 arguments are passed in
From:
"peterzhu2118 (Peter Zhu)" <noreply@...>
Date:
2022-08-25 13:41:23 UTC
List:
ruby-core #109692
Issue #18978 has been reported by peterzhu2118 (Peter Zhu).
----------------------------------------
Bug #18978: Unexpected behaviour in Time.utc and Time.local when 8 arguments are passed in
https://bugs.ruby-lang.org/issues/18978
* 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/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>