[前][次][番号順一覧][スレッド一覧]

ruby-changes:44526

From: akr <ko1@a...>
Date: Sat, 5 Nov 2016 23:59:56 +0900 (JST)
Subject: [ruby-changes:44526] akr:r56599 (trunk): fix vtm_add_offset yday on last day of year.

akr	2016-11-05 23:59:51 +0900 (Sat, 05 Nov 2016)

  New Revision: 56599

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56599

  Log:
    fix vtm_add_offset yday on last day of year.
    
    * time.c (vtm_add_offset): Fix yday on last day of year.
      [ruby-core:72878] [Bug #11994] Fixed by Andrew White.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_time.rb
    trunk/time.c
Index: test/ruby/test_time.rb
===================================================================
--- test/ruby/test_time.rb	(revision 56598)
+++ test/ruby/test_time.rb	(revision 56599)
@@ -1072,4 +1072,21 @@ class TestTime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time.rb#L1072
     assert_equal now2, now3
     assert_equal now2.zone, now3.zone
   end
+
+  def test_strftime_yearday_on_last_day_of_year
+    t = Time.utc(2015, 12, 31, 0, 0, 0)
+    assert_equal("365", t.strftime("%j"))
+    t = Time.utc(2016, 12, 31, 0, 0, 0)
+    assert_equal("366", t.strftime("%j"))
+
+    t = Time.utc(2015, 12, 30, 20, 0, 0).getlocal("+05:00")
+    assert_equal("365", t.strftime("%j"))
+    t = Time.utc(2016, 12, 30, 20, 0, 0).getlocal("+05:00")
+    assert_equal("366", t.strftime("%j"))
+
+    t = Time.utc(2016, 1, 1, 1, 0, 0).getlocal("-05:00")
+    assert_equal("365", t.strftime("%j"))
+    t = Time.utc(2017, 1, 1, 1, 0, 0).getlocal("-05:00")
+    assert_equal("366", t.strftime("%j"))
+  end
 end
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56598)
+++ ChangeLog	(revision 56599)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Nov  5 23:46:03 2016  Tanaka Akira  <akr@f...>
+
+	* time.c (vtm_add_offset): Fix yday on last day of year.
+	  [ruby-core:72878] [Bug #11994] Fixed by Andrew White.
+
 Sat Nov  5 23:30:41 2016  Shugo Maeda  <shugo@r...>
 
 	* lib/net/http.rb (Net::HTTP.post): new convenience method to send
@@ -64,7 +69,7 @@ Sat Nov  5 17:29:06 2016  Tanaka Akira https://github.com/ruby/ruby/blob/trunk/ChangeLog#L69
 
 	* lib/resolv.rb (Resolv::DNS#extract_resources): Use each_resource
 	  instead of each_answer.
-	  [ruby-core:75461] [Bug#12372] reported by Rafael Fernandez Lopez.
+	  [ruby-core:75461] [Bug #12372] reported by Rafael Fernandez Lopez.
 
 Sat Nov  5 17:18:24 2016  NARUSE, Yui  <naruse@r...>
 
@@ -106,7 +111,7 @@ Sat Nov  5 13:52:52 2016  Akinori MUSHA https://github.com/ruby/ruby/blob/trunk/ChangeLog#L111
 Sat Nov  5 12:14:31 2016  Tanaka Akira  <akr@f...>
 
 	* ext/pathname/pathname.c (Pathname#empty?): New method.
-	  [ruby-core:76404] [Feature#12596] Proposed by John Backus.
+	  [ruby-core:76404] [Feature #12596] Proposed by John Backus.
 
 Sat Nov  5 11:53:02 2016  Shugo Maeda  <shugo@r...>
 
Index: time.c
===================================================================
--- time.c	(revision 56598)
+++ time.c	(revision 56599)
@@ -1889,7 +1889,7 @@ vtm_add_offset(struct vtm *vtm, VALUE of https://github.com/ruby/ruby/blob/trunk/time.c#L1889
                 vtm->mday = 31;
                 vtm->mon = 12; /* December */
                 vtm->year = sub(vtm->year, INT2FIX(1));
-                vtm->yday = leap_year_v_p(vtm->year) ? 365 : 364;
+                vtm->yday = leap_year_v_p(vtm->year) ? 366 : 365;
             }
             else if (vtm->mday == 1) {
                 const int *days_in_month = leap_year_v_p(vtm->year) ?

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]