ruby-changes:62191
From: Nobuyoshi <ko1@a...>
Date: Sun, 12 Jul 2020 23:31:12 +0900 (JST)
Subject: [ruby-changes:62191] 99a9c3fe2e (master): Fixed yday and wday with timezone [Bug #17024]
https://git.ruby-lang.org/ruby.git/commit/?id=99a9c3fe2e From 99a9c3fe2eaab8157765d792dc871da6daea0327 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 12 Jul 2020 14:09:48 +0900 Subject: Fixed yday and wday with timezone [Bug #17024] diff --git a/spec/ruby/core/time/new_spec.rb b/spec/ruby/core/time/new_spec.rb index 3cafd46..1a2f93e 100644 --- a/spec/ruby/core/time/new_spec.rb +++ b/spec/ruby/core/time/new_spec.rb @@ -129,6 +129,10 @@ ruby_version_is "2.6" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/time/new_spec.rb#L129 time.zone.should == zone time.utc_offset.should == 5*3600+30*60 + ruby_version_is "2.8" do + time.wday.should == 6 + time.yday.should == 1 + end end it "accepts timezone argument that must have #local_to_utc and #utc_to_local methods" do diff --git a/test/ruby/test_time_tz.rb b/test/ruby/test_time_tz.rb index a95f9e7..1d86d0c 100644 --- a/test/ruby/test_time_tz.rb +++ b/test/ruby/test_time_tz.rb @@ -604,6 +604,8 @@ module TestTimeTZ::WithTZ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time_tz.rb#L604 assert_equal([2018, 9, 1, 12, 0, 0, tz], [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.zone]) h, m = (-utc_offset / 60).divmod(60) assert_equal(time_class.utc(2018, 9, 1, 12+h, m, 0).to_i, t.to_i) + assert_equal(6, t.wday) + assert_equal(244, t.yday) end def subtest_now(time_class, tz, tzarg, tzname, abbr, utc_offset) diff --git a/time.c b/time.c index 1cdeeb8..b1dfce0 100644 --- a/time.c +++ b/time.c @@ -4580,14 +4580,15 @@ time_wday(VALUE time) https://github.com/ruby/ruby/blob/trunk/time.c#L4580 GetTimeval(time, tobj); MAKE_TM(time, tobj); + if (tobj->vtm.wday == VTM_WDAY_INITVAL) { + VALUE zone = tobj->vtm.zone; + if (!NIL_P(zone)) zone_localtime(zone, time); + } return INT2FIX((int)tobj->vtm.wday); } #define wday_p(n) {\ - struct time_object *tobj;\ - GetTimeval(time, tobj);\ - MAKE_TM(time, tobj);\ - return (tobj->vtm.wday == (n)) ? Qtrue : Qfalse;\ + return (time_wday(time) == INT2FIX(n)) ? Qtrue : Qfalse; \ } /* @@ -4719,6 +4720,10 @@ time_yday(VALUE time) https://github.com/ruby/ruby/blob/trunk/time.c#L4720 GetTimeval(time, tobj); MAKE_TM(time, tobj); + if (tobj->vtm.yday == 0) { + VALUE zone = tobj->vtm.zone; + if (!NIL_P(zone)) zone_localtime(zone, time); + } return INT2FIX(tobj->vtm.yday); } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/