summaryrefslogtreecommitdiffstats
path: root/lib/date.rb
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-07 15:08:42 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-07 15:08:42 +0000
commitbb74408e70b1813b00f16de0212c1c91c084aea6 (patch)
tree6b0bdf1fba1b52c4a9281a03f265a71998a378f0 /lib/date.rb
parent980541b7fcce7d1a1664841139988b11d18e0a07 (diff)
downloadruby-bb74408e70b1813b00f16de0212c1c91c084aea6.tar.gz
ruby-bb74408e70b1813b00f16de0212c1c91c084aea6.tar.xz
ruby-bb74408e70b1813b00f16de0212c1c91c084aea6.zip
* lib/date.rb (today,now): should produce own instances.
[ruby-talk:317020] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@19705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/date.rb')
-rw-r--r--lib/date.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/date.rb b/lib/date.rb
index 5ac8bf03d..3da3d21f8 100644
--- a/lib/date.rb
+++ b/lib/date.rb
@@ -1790,12 +1790,23 @@ class Date
# 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