1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/date/date_core.c (datetime_s_*): canonicalize 24 o'clock.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2011-06-21 11:42:50 +00:00
parent c9aef84c7a
commit 5b16ddf504
3 changed files with 34 additions and 3 deletions

View file

@ -1,3 +1,7 @@
Tue Jun 21 20:38:47 2011 Tadayoshi Funaba <tadf@dotrb.org>
* ext/date/date_core.c (datetime_s_*): canonicalize 24 o'clock.
Tue Jun 21 19:56:07 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* internal.h: move rb_thread_io_blocking_region() declaration

View file

@ -3087,6 +3087,14 @@ s_trunc(VALUE s, VALUE *fr)
}\
}
#define canon24oc() \
{\
if (rh == 24) {\
rh = 0;\
fr2 = f_add(fr2, INT2FIX(1));\
}\
}
#define add_frac() \
{\
if (f_nonzero_p(fr2))\
@ -7188,6 +7196,7 @@ datetime_s_jd(int argc, VALUE *argv, VALUE klass)
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
rb_raise(rb_eArgError, "invalid date");
canon24oc();
decode_jd(jd, &nth, &rjd);
rjd2 = jd_local_to_utc(rjd,
@ -7265,6 +7274,7 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
rb_raise(rb_eArgError, "invalid date");
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
rb_raise(rb_eArgError, "invalid date");
canon24oc();
rjd2 = jd_local_to_utc(rjd,
time_to_df(rh, rmin, rs),
@ -7344,6 +7354,7 @@ datetime_s_civil(int argc, VALUE *argv, VALUE klass)
rb_raise(rb_eArgError, "invalid date");
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
rb_raise(rb_eArgError, "invalid date");
canon24oc();
ret = d_complex_new_internal(klass,
nth, 0,
@ -7364,6 +7375,7 @@ datetime_s_civil(int argc, VALUE *argv, VALUE klass)
rb_raise(rb_eArgError, "invalid date");
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
rb_raise(rb_eArgError, "invalid date");
canon24oc();
rjd2 = jd_local_to_utc(rjd,
time_to_df(rh, rmin, rs),
@ -7442,7 +7454,7 @@ datetime_s_commercial(int argc, VALUE *argv, VALUE klass)
rb_raise(rb_eArgError, "invalid date");
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
rb_raise(rb_eArgError, "invalid date");
canon24oc();
rjd2 = jd_local_to_utc(rjd,
time_to_df(rh, rmin, rs),
@ -7513,11 +7525,11 @@ datetime_s_weeknum(int argc, VALUE *argv, VALUE klass)
rb_raise(rb_eArgError, "invalid date");
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
rb_raise(rb_eArgError, "invalid date");
canon24oc();
rjd2 = jd_local_to_utc(rjd,
time_to_df(rh, rmin, rs),
rof);
ret = d_complex_new_internal(klass,
nth, rjd2,
0, INT2FIX(0),
@ -7582,11 +7594,11 @@ datetime_s_nth_kday(int argc, VALUE *argv, VALUE klass)
rb_raise(rb_eArgError, "invalid date");
if (!c_valid_time_p(h, min, s, &rh, &rmin, &rs))
rb_raise(rb_eArgError, "invalid date");
canon24oc();
rjd2 = jd_local_to_utc(rjd,
time_to_df(rh, rmin, rs),
rof);
ret = d_complex_new_internal(klass,
nth, rjd2,
0, INT2FIX(0),

View file

@ -180,6 +180,21 @@ class TestSH < Test::Unit::TestCase
[d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset])
end
def test_canon24oc
d = DateTime.jd(2451943,24)
assert_equal([2001, 2, 3, 0, 0, 0, 0],
[d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset])
d = DateTime.ordinal(2001,33,24)
assert_equal([2001, 2, 3, 0, 0, 0, 0],
[d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset])
d = DateTime.new(2001,2,2,24)
assert_equal([2001, 2, 3, 0, 0, 0, 0],
[d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset])
d = DateTime.commercial(2001,5,5,24)
assert_equal([2001, 2, 3, 0, 0, 0, 0],
[d.year, d.mon, d.mday, d.hour, d.min, d.sec, d.offset])
end
def test_zone
d = Date.new(2001, 2, 3)
assert_equal(Encoding::US_ASCII, d.send(:zone).encoding)