ruby-changes:33741
From: tadf <ko1@a...>
Date: Mon, 5 May 2014 05:56:35 +0900 (JST)
Subject: [ruby-changes:33741] tadf:r45822 (trunk): * ext/date/date_core.c (rt_rewrite_frags): a new feature (not a
tadf 2014-05-05 05:56:28 +0900 (Mon, 05 May 2014) New Revision: 45822 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45822 Log: * ext/date/date_core.c (rt_rewrite_frags): a new feature (not a bug fix) of strptime. applies offset even if the given date is not local time (%s and %Q). This is an exceptional feature and I do NOT recommend to use this at all. Thank you git community. Modified files: trunk/ChangeLog trunk/ext/date/date_core.c trunk/test/date/test_date_strptime.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 45821) +++ ChangeLog (revision 45822) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon May 5 01:12:27 2014 Tadayoshi Funaba <tadf@d...> + + * ext/date/date_core.c (rt_rewrite_frags): a new feature (not a + bug fix) of strptime. applies offset even if the given date is + not local time (%s and %Q). This is an exceptional feature and + I do NOT recommend to use this at all. Thank you git community. + Sun May 4 20:51:32 2014 Tanaka Akira <akr@f...> * lib/time.rb (Time.force_zone!): Use usual local time if it has Index: ext/date/date_core.c =================================================================== --- ext/date/date_core.c (revision 45821) +++ ext/date/date_core.c (revision 45822) @@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L1 /* - date_core.c: Coded by Tadayoshi Funaba 2010-2013 + date_core.c: Coded by Tadayoshi Funaba 2010-2014 */ #include "ruby.h" @@ -3667,7 +3667,11 @@ rt_rewrite_frags(VALUE hash) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L3667 seconds = ref_hash("seconds"); if (!NIL_P(seconds)) { - VALUE d, h, min, s, fr; + VALUE offset, d, h, min, s, fr; + + offset = ref_hash("offset"); + if (!NIL_P(offset)) + seconds = f_add(seconds, offset); d = f_idiv(seconds, INT2FIX(DAY_IN_SECONDS)); fr = f_mod(seconds, INT2FIX(DAY_IN_SECONDS)); @@ -3687,7 +3691,6 @@ rt_rewrite_frags(VALUE hash) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L3691 set_hash("sec", s); set_hash("sec_fraction", fr); del_hash("seconds"); - del_hash("offset"); } return hash; } Index: test/date/test_date_strptime.rb =================================================================== --- test/date/test_date_strptime.rb (revision 45821) +++ test/date/test_date_strptime.rb (revision 45822) @@ -493,4 +493,21 @@ class TestDateStrptime < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/date/test_date_strptime.rb#L493 assert_equal(s0, s) end + def test_sz + d = DateTime.strptime('0 -0200', '%s %z') + assert_equal([1969, 12, 31, 22, 0, 0], [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + assert_equal(Rational(-2, 24), d.offset) + d = DateTime.strptime('9 +0200', '%s %z') + assert_equal([1970, 1, 1, 2, 0, 9], [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + assert_equal(Rational(2, 24), d.offset) + + d = DateTime.strptime('0 -0200', '%Q %z') + assert_equal([1969, 12, 31, 22, 0, 0], [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + assert_equal(Rational(-2, 24), d.offset) + d = DateTime.strptime('9000 +0200', '%Q %z') + assert_equal([1970, 1, 1, 2, 0, 9], [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) + assert_equal(Rational(2, 24), d.offset) + + end + end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/