ruby-changes:53861
From: nobu <ko1@a...>
Date: Wed, 28 Nov 2018 23:18:48 +0900 (JST)
Subject: [ruby-changes:53861] nobu:r66078 (trunk): Time.at in: tz
nobu 2018-11-28 23:08:33 +0900 (Wed, 28 Nov 2018) New Revision: 66078 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66078 Log: Time.at in: tz Modified files: trunk/test/ruby/test_time_tz.rb trunk/time.c Index: time.c =================================================================== --- time.c (revision 66077) +++ time.c (revision 66078) @@ -2686,7 +2686,7 @@ get_scale(VALUE unit) https://github.com/ruby/ruby/blob/trunk/time.c#L2686 * can be an Integer, Float, Rational, or other Numeric. * non-portable feature allows the offset to be negative on some systems. * - * If +tz+ argument is given, the result is in that timezone or UTC offset, or + * If +in+ argument is given, the result is in that timezone or UTC offset, or * if a numeric argument is given, the result is in local time. * * Time.at(0) #=> 1969-12-31 18:00:00 -0600 @@ -2701,13 +2701,19 @@ get_scale(VALUE unit) https://github.com/ruby/ruby/blob/trunk/time.c#L2701 static VALUE time_s_at(int argc, VALUE *argv, VALUE klass) { - VALUE time, t, unit = Qundef, zone = Qnil; + VALUE time, t, unit = Qundef, zone = Qundef, opts; wideval_t timew; - if (argc > 1 && rb_obj_respond_to(argv[argc-1], id_utc_to_local, Qfalse)) { - zone = argv[--argc]; + argc = rb_scan_args(argc, argv, "12:", &time, &t, &unit, &opts); + if (!NIL_P(opts)) { + ID ids[1]; + VALUE vals[numberof(ids)]; + + CONST_ID(ids[0], "in"); + rb_get_kwargs(opts, ids, 0, 1, vals); + zone = vals[0]; } - if (rb_scan_args(argc, argv, "12", &time, &t, &unit) >= 2) { + if (argc >= 2) { int scale = argc == 3 ? get_scale(unit) : 1000000; time = num_exact(time); t = num_exact(t); @@ -2725,7 +2731,7 @@ time_s_at(int argc, VALUE *argv, VALUE k https://github.com/ruby/ruby/blob/trunk/time.c#L2731 timew = rb_time_magnify(v2w(num_exact(time))); t = time_new_timew(klass, timew); } - if (!NIL_P(zone)) { + if (zone != Qundef) { time_zonelocal(t, zone); } Index: test/ruby/test_time_tz.rb =================================================================== --- test/ruby/test_time_tz.rb (revision 66077) +++ test/ruby/test_time_tz.rb (revision 66078) @@ -547,11 +547,11 @@ module TestTimeTZ::WithTZ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time_tz.rb#L547 def subtest_at(time_class, tz, tzarg, tzname, abbr, utc_offset) h, m = (utc_offset / 60).divmod(60) utc = time_class.utc(2018, 9, 1, 12, 0, 0) - t = time_class.at(utc, tzarg) + t = time_class.at(utc, in: tzarg) assert_equal([2018, 9, 1, 12+h, m, 0, tz], [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.zone]) assert_equal(utc.to_i, t.to_i) utc = utc.to_i - t = time_class.at(utc, tzarg) + t = time_class.at(utc, in: tzarg) assert_equal([2018, 9, 1, 12+h, m, 0, tz], [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.zone]) assert_equal(utc, t.to_i) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/