1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

updated based on date2 3.9.7.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11279 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2006-11-05 10:55:20 +00:00
parent c676ed3b4d
commit d304aa6382
2 changed files with 39 additions and 9 deletions

View file

@ -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]

View file

@ -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