* 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.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2014-05-04 20:56:28 +00:00
Родитель d9087ffebc
Коммит a72f9f3476
3 изменённых файлов: 30 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Mon May 5 01:12:27 2014 Tadayoshi Funaba <tadf@dotrb.org>
* 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@fsij.org>
* lib/time.rb (Time.force_zone!): Use usual local time if it has

Просмотреть файл

@ -1,5 +1,5 @@
/*
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)
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)
set_hash("sec", s);
set_hash("sec_fraction", fr);
del_hash("seconds");
del_hash("offset");
}
return hash;
}

Просмотреть файл

@ -493,4 +493,21 @@ class TestDateStrptime < Test::Unit::TestCase
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