summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-29 02:53:30 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-29 02:53:30 +0000
commit3a23aad61c4a07a092aa9cba10f899d58d17c510 (patch)
treea776c03e13c2b6e14430fc77301372ac3828aa44 /lib
parentb789e70a315b1df715c44389ba46503209a28518 (diff)
merge revision(s) 19707:
* lib/date.rb (today,now): should produce own instances. [ruby-talk:317020] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@21864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/date.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/date.rb b/lib/date.rb
index 0dfe1bb06e..ea557313f7 100644
--- a/lib/date.rb
+++ b/lib/date.rb
@@ -1619,12 +1619,23 @@ class Date
# 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