ruby-changes:64862
From: Nobuyoshi <ko1@a...>
Date: Wed, 13 Jan 2021 20:41:31 +0900 (JST)
Subject: [ruby-changes:64862] e9b93d67ba (master): Positional and keyword arguments for timezone are exclusive
https://git.ruby-lang.org/ruby.git/commit/?id=e9b93d67ba From e9b93d67baf8a6add548b7e5c702665100e4b3c9 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 13 Jan 2021 18:25:07 +0900 Subject: Positional and keyword arguments for timezone are exclusive [Feature #17485] diff --git a/test/ruby/test_time_tz.rb b/test/ruby/test_time_tz.rb index 7c89b35..3783890 100644 --- a/test/ruby/test_time_tz.rb +++ b/test/ruby/test_time_tz.rb @@ -607,6 +607,7 @@ module TestTimeTZ::WithTZ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time_tz.rb#L607 assert_equal(6, t.wday) assert_equal(244, t.yday) assert_equal(t, time_class.new(2018, 9, 1, 12, in: tzarg)) + assert_raise(ArgumentError) {time_class.new(2018, 9, 1, 12, 0, 0, tzarg, in: tzarg)} end def subtest_now(time_class, tz, tzarg, tzname, abbr, utc_offset) diff --git a/timev.rb b/timev.rb index d0989cb..202d5b3 100644 --- a/timev.rb +++ b/timev.rb @@ -107,9 +107,19 @@ class Time https://github.com/ruby/ruby/blob/trunk/timev.rb#L107 # (t4-t3)/3600.0 #=> 2.466666666666667 # (t6-t5)/3600.0 #=> 1.95 # (t8-t7)/3600.0 #=> 13.416666666666666 - def initialize(year = (now = true), mon = nil, mday = nil, hour = nil, min = nil, sec = nil, zone = nil, in: zone) - zone = __builtin.arg!(:in) - return __builtin.time_init_now(zone) if now + def initialize(year = (now = true), mon = nil, mday = nil, hour = nil, min = nil, sec = nil, zone = nil, in: nil) + if zone + if __builtin.arg!(:in) + raise ArgumentError, "timezone argument given as positional and keyword arguments" + end + else + zone = __builtin.arg!(:in) + end + + if now + return __builtin.time_init_now(zone) + end + __builtin.time_init_args(year, mon, mday, hour, min, sec, zone) end end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/