diff options
author | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-11-05 10:55:20 +0000 |
---|---|---|
committer | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-11-05 10:55:20 +0000 |
commit | d304aa6382747bc2c5094c9d3081f6e8260e5d96 (patch) | |
tree | f3b4f01d6449bbed14c1cd5ca6ccc1bc48cfe728 | |
parent | c676ed3b4d21189da6eda643f942fb37faf4c010 (diff) | |
download | ruby-d304aa6382747bc2c5094c9d3081f6e8260e5d96.tar.gz |
updated based on date2 3.9.7.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11279 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/date.rb | 44 |
2 files changed, 39 insertions, 9 deletions
@@ -1,3 +1,7 @@ +Sun Nov 5 19:52:19 2006 Tadayoshi Funaba <tadf@dotrb.org> + + * lib/date.rb: updated based on date2 3.9.7. + Sat Nov 4 13:09:31 2006 Shugo Maeda <shugo@ruby-lang.org> * lib/net/imap.rb: accept NOMODSEQ. [ruby-core:9002] diff --git a/lib/date.rb b/lib/date.rb index 5283b9ceb0..bbfa5dc106 100644 --- a/lib/date.rb +++ b/lib/date.rb @@ -6,7 +6,7 @@ # Documentation: William Webber <william@williamwebber.com> # #-- -# $Id: date.rb,v 2.28 2006-10-13 22:04:07+09 tadf Exp $ +# $Id: date.rb,v 2.29 2006-11-05 18:21:29+09 tadf Exp $ #++ # # == Overview @@ -1124,7 +1124,13 @@ class Date def gregorian() new_start(self.class::GREGORIAN) end def offset() @of end - def new_offset(of=0) self.class.new0(@ajd, of, @sg) end + + def new_offset(of=0) + if String === of + of = (self.class.zone_to_diff(of) || 0).to_r/86400 + end + self.class.new0(@ajd, of, @sg) + end private :offset, :new_offset @@ -1229,11 +1235,16 @@ class Date def next_year(n=1) self >> n * 12 end def prev_year(n=1) self << n * 12 end + require 'enumerator' + # Step the current date forward +step+ days at a # time (or backward, if +step+ is negative) until # we reach +limit+ (inclusive), yielding the resultant # date at each step. def step(limit, step=1) # :yield: date + unless block_given? + return to_enum(:step, limit, step) + end da = self op = %w(- <= >=)[step <=> 0] while da.__send__(op, limit) @@ -1388,6 +1399,9 @@ class DateTime < Date (fr = valid_time?(h, min, s)) raise ArgumentError, 'invalid date' end + if String === of + of = (zone_to_diff(of) || 0).to_r/86400 + end new0(jd_to_ajd(jd, fr, of), of, sg) end @@ -1410,6 +1424,9 @@ class DateTime < Date (fr = valid_time?(h, min, s)) raise ArgumentError, 'invalid date' end + if String === of + of = (zone_to_diff(of) || 0).to_r/86400 + end new0(jd_to_ajd(jd, fr, of), of, sg) end @@ -1432,6 +1449,9 @@ class DateTime < Date (fr = valid_time?(h, min, s)) raise ArgumentError, 'invalid date' end + if String === of + of = (zone_to_diff(of) || 0).to_r/86400 + end new0(jd_to_ajd(jd, fr, of), of, sg) end @@ -1457,6 +1477,9 @@ class DateTime < Date (fr = valid_time?(h, min, s)) raise ArgumentError, 'invalid date' end + if String === of + of = (zone_to_diff(of) || 0).to_r/86400 + end new0(jd_to_ajd(jd, fr, of), of, sg) end @@ -1547,7 +1570,14 @@ 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) Time.now.to_date .new_start(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 + + private_class_method :now end @@ -1565,12 +1595,8 @@ class DateTime < Date def to_date() Date.new0(self.class.jd_to_ajd(jd, 0, 0), 0, @sg) end def to_datetime() self end - class << self; undef_method :today 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 + private_class_method :today + public_class_method :now end |