ruby-changes:8178
From: tadf <ko1@a...>
Date: Wed, 8 Oct 2008 00:09:03 +0900 (JST)
Subject: [ruby-changes:8178] Ruby:r19705 (trunk): * lib/date.rb (today,now): should produce own instances.
tadf 2008-10-08 00:08:42 +0900 (Wed, 08 Oct 2008) New Revision: 19705 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19705 Log: * lib/date.rb (today,now): should produce own instances. [ruby-talk:317020] Modified files: trunk/ChangeLog trunk/lib/date.rb trunk/test/date/test_date.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 19704) +++ ChangeLog (revision 19705) @@ -1,3 +1,8 @@ +Wed Oct 8 00:03:39 2008 Tadayoshi Funaba <tadf@d...> + + * lib/date.rb (today,now): should produce own instances. + [ruby-talk:317020] + Tue Oct 7 16:43:51 2008 NARUSE, Yui <naruse@r...> * ext/json/lib/json/pure/generator.rb (utf8_to_json): Index: lib/date.rb =================================================================== --- lib/date.rb (revision 19704) +++ lib/date.rb (revision 19705) @@ -1790,12 +1790,23 @@ # Create a new Date object representing today. # # +sg+ specifies the Day of Calendar Reform. - def self.today(sg=ITALY) Time.now.to_date .new_start(sg) end + def self.today(sg=ITALY) + t = Time.now + jd = civil_to_jd(t.year, t.mon, t.mday, sg) + new!(jd_to_ajd(jd, 0, 0), 0, sg) + end # Create a new DateTime object representing the current time. # # +sg+ specifies the Day of Calendar Reform. - def self.now (sg=ITALY) Time.now.to_datetime.new_start(sg) end + def self.now(sg=ITALY) + t = Time.now + jd = civil_to_jd(t.year, t.mon, t.mday, sg) + fr = time_to_day_fraction(t.hour, t.min, [t.sec, 59].min) + + Rational(t.nsec, 86400_000_000_000) + of = Rational(t.utc_offset, 86400) + new!(jd_to_ajd(jd, fr, of), of, sg) + end private_class_method :now Index: test/date/test_date.rb =================================================================== --- test/date/test_date.rb (revision 19704) +++ test/date/test_date.rb (revision 19705) @@ -36,6 +36,11 @@ dt = DateTimeSub.new assert_instance_of(DateSub, d) + assert_instance_of(DateTimeSub, dt) + + assert_instance_of(DateSub, DateSub.today) + assert_instance_of(DateTimeSub, DateTimeSub.now) + assert_equal('#<DateSub: -1/2,0,2299161>', d.inspect) assert_equal('-4712-01-01', d.to_s) assert_equal('-4712-01-01T00:00:00+00:00', dt.to_s) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/