ruby-changes:20137
From: tadf <ko1@a...>
Date: Tue, 21 Jun 2011 20:42:58 +0900 (JST)
Subject: [ruby-changes:20137] tadf:r32185 (trunk): * ext/date/date_core.c (datetime_s_*): canonicalize 24 o'clock.
tadf 2011-06-21 20:42:50 +0900 (Tue, 21 Jun 2011) New Revision: 32185 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32185 Log: * ext/date/date_core.c (datetime_s_*): canonicalize 24 o'clock. Modified files: trunk/ChangeLog trunk/ext/date/date_core.c trunk/test/date/test_switch_hitter.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 32184) +++ ChangeLog (revision 32185) @@ -1,3 +1,7 @@ +Tue Jun 21 20:38:47 2011 Tadayoshi Funaba <tadf@d...> + + * ext/date/date_core.c (datetime_s_*): canonicalize 24 o'clock. + Tue Jun 21 19:56:07 2011 KOSAKI Motohiro <kosaki.motohiro@g...> * internal.h: move rb_thread_io_blocking_region() declaration Index: ext/date/date_core.c =================================================================== --- ext/date/date_core.c (revision 32184) +++ ext/date/date_core.c (revision 32185) @@ -3087,6 +3087,14 @@ }\ } +#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 @@ 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 @@ 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 @@ 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 @@ 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,8 +7454,8 @@ 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); @@ -7513,11 +7525,11 @@ 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 @@ 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), Index: test/date/test_switch_hitter.rb =================================================================== --- test/date/test_switch_hitter.rb (revision 32184) +++ test/date/test_switch_hitter.rb (revision 32185) @@ -180,6 +180,21 @@ [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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/