[前][次][番号順一覧][スレッド一覧]

ruby-changes:8179

From: tadf <ko1@a...>
Date: Wed, 8 Oct 2008 00:10:53 +0900 (JST)
Subject: [ruby-changes:8179] Ruby:r19707 (ruby_1_8): * lib/date.rb (today,now): should produce own instances.

tadf	2008-10-08 00:10:41 +0900 (Wed, 08 Oct 2008)

  New Revision: 19707

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19707

  Log:
    * lib/date.rb (today,now): should produce own instances.
      [ruby-talk:317020]

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/lib/date.rb

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 19706)
+++ ruby_1_8/ChangeLog	(revision 19707)
@@ -1,3 +1,8 @@
+Wed Oct  8 00:09:13 2008  Tadayoshi Funaba  <tadf@d...>
+
+	* lib/date.rb (today,now): should produce own instances.
+	  [ruby-talk:317020]
+
 Mon Oct  6 15:26:19 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* gc.c (gc_mark_children): ignores T_ZOMBIE.
Index: ruby_1_8/lib/date.rb
===================================================================
--- ruby_1_8/lib/date.rb	(revision 19706)
+++ ruby_1_8/lib/date.rb	(revision 19707)
@@ -1660,12 +1660,23 @@
   # Create a new Date object representing today.
   #
   # +sg+ specifies the Day of Calendar Reform.
-  def self.today(sg=ITALY) Time.now.__send__(: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.__send__(: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.usec, 86400_000_000)
+    of = Rational(t.utc_offset, 86400)
+    new!(jd_to_ajd(jd, fr, of), of, sg)
+  end
 
   private_class_method :now
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]