summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-08-11 07:24:11 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-08-11 07:24:11 +0000
commitc5fb7cf4fb7759ae020032f344460c2accef2bc7 (patch)
tree37621427e11c9e2bf672c05c25b24bf0d365a639 /lib
parentb0faee9b9cd5a747e226a2c64f33588b2b8f4e6c (diff)
1.3.8 to be, final beta (hopefully)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/date2.rb182
-rw-r--r--lib/debug.rb8
-rw-r--r--lib/telnet.rb18
3 files changed, 114 insertions, 94 deletions
diff --git a/lib/date2.rb b/lib/date2.rb
index a1045a9..58bfbe5 100644
--- a/lib/date2.rb
+++ b/lib/date2.rb
@@ -1,5 +1,5 @@
-# date.rb: Written by Tadayoshi Funaba 1998, 1999
-# $Id: date.rb,v 1.7 1999/03/06 02:05:59 tadf Exp $
+# date2.rb: Written by Tadayoshi Funaba 1998, 1999
+# $Id: date2.rb,v 1.13 1999/08/11 01:10:02 tadf Exp $
class Date
@@ -12,12 +12,21 @@ class Date
DAYNAMES = [ 'Sunday', 'Monday', 'Tuesday',
'Wednesday', 'Thursday', 'Friday', 'Saturday' ]
- ITALY = 2299161 # Oct 15, 1582
+ ITALY = 2299161 # Oct 15, 1582
ENGLAND = 2361222 # Sept 14, 1752
class << self
- def civil_to_jd(y, m, d, gs=true)
+ def os? (jd, sg)
+ case sg
+ when Numeric; jd < sg
+ else; not sg
+ end
+ end
+
+ def ns? (jd, sg) not os?(jd, sg) end
+
+ def civil_to_jd(y, m, d, sg=true)
if m <= 2
y -= 1
m += 12
@@ -27,16 +36,14 @@ class Date
jd = (365.25 * (y + 4716)).to_i +
(30.6001 * (m + 1)).to_i +
d + b - 1524
- unless
- (if gs.kind_of? Numeric then jd >= gs else gs end)
+ if os?(jd, sg)
jd -= b
end
jd
end
- def jd_to_civil(jd, gs=true)
- unless
- (if gs.kind_of? Numeric then jd >= gs else gs end)
+ def jd_to_civil(jd, sg=true)
+ if os?(jd, sg)
a = jd
else
x = ((jd - 1867216.25) / 36524.25).to_i
@@ -57,87 +64,89 @@ class Date
return y, m, dom
end
- def ordinal_to_jd(y, d, gs=true)
- civil_to_jd(y, 1, d, gs)
+ def ordinal_to_jd(y, d, sg=true)
+ civil_to_jd(y, 1, d, sg)
end
- def jd_to_ordinal(jd, gs=true)
- y, *_ = jd_to_civil(jd, gs)
- ns = if gs.kind_of? Numeric then jd >= gs else gs end
- pl = civil_to_jd(y - 1, 12, 31, ns)
+ def jd_to_ordinal(jd, sg=true)
+ y = jd_to_civil(jd, sg)[0]
+ pl = civil_to_jd(y - 1, 12, 31, ns?(jd, sg))
doy = jd - pl
return y, doy
end
- def mjd_to_jd(mjd)
- mjd + 2400000.5
- end
-
- def jd_to_mjd(jd)
- jd - 2400000.5
- end
-
- def tjd_to_jd(tjd)
- tjd + 2440000.5
- end
-
- def jd_to_tjd(jd)
- jd - 2440000.5
- end
+ def mjd_to_jd(mjd) mjd + 2400000.5 end
+ def jd_to_mjd(jd) jd - 2400000.5 end
+ def tjd_to_jd(tjd) tjd + 2440000.5 end
+ def jd_to_tjd(jd) jd - 2440000.5 end
- def julian_leap? (y)
- y % 4 == 0
- end
-
- def gregorian_leap? (y)
- y % 4 == 0 and y % 100 != 0 or y % 400 == 0
- end
+ def julian_leap? (y) y % 4 == 0 end
+ def gregorian_leap? (y) y % 4 == 0 and y % 100 != 0 or y % 400 == 0 end
alias_method :leap?, :gregorian_leap?
- def exist3? (y, m, d, gs=true)
- jd = civil_to_jd(y, m, d, gs)
- if [y, m, d] == jd_to_civil(jd, gs)
+ def exist3? (y, m, d, sg=ITALY)
+ if m < 0
+ m += 13
+ end
+ if d < 0
+ ljd = nil
+ 31.downto 1 do |ld|
+ break if ljd = exist3?(y, m, ld, sg)
+ end
+ x = y * 12 + m
+ ny = x / 12
+ nm = x % 12 + 1
+ d = jd_to_civil(civil_to_jd(ny, nm, 1, ns?(ljd, sg)) + d,
+ ns?(ljd, sg))[-1]
+ end
+ jd = civil_to_jd(y, m, d, sg)
+ if [y, m, d] == jd_to_civil(jd, sg)
jd
end
end
alias_method :exist?, :exist3?
- def new3(y=-4712, m=1, d=1, gs=ITALY)
- unless jd = exist3?(y, m, d, gs)
+ def new3(y=-4712, m=1, d=1, sg=ITALY)
+ unless jd = exist3?(y, m, d, sg)
fail ArgumentError, 'invalid date'
end
- new(jd, gs)
+ new(jd, sg)
end
- def exist2? (y, d, gs=true)
- jd = ordinal_to_jd(y, d, gs)
- if [y, d] == jd_to_ordinal(jd, gs)
+ def exist2? (y, d, sg=ITALY)
+ if d < 0
+ ljd = nil
+ 366.downto 1 do |ld|
+ break if ljd = exist2?(y, ld, sg)
+ end
+ ny = y + 1
+ d = jd_to_ordinal(ordinal_to_jd(ny, 1, ns?(ljd, sg)) + d,
+ ns?(ljd, sg))[-1]
+ end
+ jd = ordinal_to_jd(y, d, sg)
+ if [y, d] == jd_to_ordinal(jd, sg)
jd
end
end
- def new2(y=-4712, d=1, gs=ITALY)
- unless jd = exist2?(y, d, gs)
+ def new2(y=-4712, d=1, sg=ITALY)
+ unless jd = exist2?(y, d, sg)
fail ArgumentError, 'invalid date'
end
- new(jd, gs)
+ new(jd, sg)
end
- def today(gs=ITALY)
- new(civil_to_jd(*(Time.now.to_a[3..5].reverse << gs)), gs)
+ def today(sg=ITALY)
+ new(civil_to_jd(*(Time.now.to_a[3..5].reverse << sg)), sg)
end
end
- def initialize(jd=0, gs=ITALY)
- @jd, @gs = jd, gs
- end
+ def initialize(jd=0, sg=ITALY) @jd, @sg = jd, sg end
- def jd
- @jd
- end
+ def jd() @jd end
def mjd
def self.mjd() @mjd end
@@ -152,8 +161,10 @@ class Date
def civil
def self.year() @year end
def self.mon() @mon end
+ def self.month() @mon end
def self.mday() @mday end
- @year, @mon, @mday = Date.jd_to_civil(@jd, @gs)
+ def self.day() @mday end
+ @year, @mon, @mday = Date.jd_to_civil(@jd, @sg)
end
private :civil
@@ -165,7 +176,7 @@ class Date
def yday
def self.yday() @yday end
- _, @yday = Date.jd_to_ordinal(@jd, @gs)
+ @yday = Date.jd_to_ordinal(@jd, @sg)[-1]
@yday
end
@@ -174,33 +185,39 @@ class Date
@mon
end
+ alias_method :month, :mon
+
def mday
civil
@mday
end
+ alias_method :day, :mday
+
def wday
def self.wday() @wday end
@wday = (@jd + 1) % 7
end
+ def os? () Date.os?(@jd, @sg) end
+ def ns? () Date.ns?(@jd, @sg) end
+
def leap?
def self.leap?() @leap_p end
- ns = if @gs.kind_of? Numeric then @jd >= @gs else @gs end
- jd = Date.civil_to_jd(year, 2, 28, ns)
- @leap_p = Date.jd_to_civil(jd + 1, ns)[1] == 2
+ @leap_p = Date.jd_to_civil(Date.civil_to_jd(year, 3, 1, ns?) - 1,
+ ns?)[-1] == 29
end
def + (other)
case other
- when Numeric; return Date.new(@jd + other, @gs)
+ when Numeric; return Date.new(@jd + other, @sg)
end
fail TypeError, 'expected numeric'
end
def - (other)
case other
- when Numeric; return Date.new(@jd - other, @gs)
+ when Numeric; return Date.new(@jd - other, @sg)
when Date; return @jd - other.jd
end
fail TypeError, 'expected numeric or date'
@@ -216,40 +233,35 @@ class Date
def downto(min)
@jd.downto(min.jd) do |jd|
- yield Date.new(jd, @gs)
+ yield Date.new(jd, @sg)
end
+ self
end
def upto(max)
@jd.upto(max.jd) do |jd|
- yield Date.new(jd, @gs)
+ yield Date.new(jd, @sg)
end
+ self
end
- def step(max, step)
- @jd.step(max.jd, step) do |jd|
- yield Date.new(jd, @gs)
+ def step(limit, step)
+ @jd.step(limit.jd, step) do |jd|
+ yield Date.new(jd, @sg)
end
+ self
end
- def eql? (other)
- self == other
- end
+ def succ() self + 1 end
- def hash
- @jd
- end
+ alias_method :next, :succ
- def to_s
- format('%04d-%02d-%02d', year, mon, mday)
- end
+ def eql? (other) self == other end
+ def hash() @jd end
+ def inspect() format('#<Date: %s,%s>', @jd, @sg) end
+ def to_s() format('%.4d-%02d-%02d', year, mon, mday) end
- def _dump(limit)
- Marshal.dump([@jd, @gs], -1)
- end
-
- def Date._load(str)
- Date.new(*Marshal.load(str))
- end
+ def _dump(limit) Marshal.dump([@jd, @sg], -1) end
+ def Date._load(str) Date.new(*Marshal.load(str)) end
end
diff --git a/lib/debug.rb b/lib/debug.rb
index 91bad1f..d2f1da8 100644
--- a/lib/debug.rb
+++ b/lib/debug.rb
@@ -157,7 +157,7 @@ class DEBUGGER__
when /^c(?:ont)?$/
return
- when /^s(?:tep)?\s+(\d+)?$/
+ when /^s(?:tep)?(?:\s+(\d+))?$/
if $1
lev = $1.to_i
else
@@ -166,7 +166,7 @@ class DEBUGGER__
@stop_next = lev
return
- when /^n(?:ext)?\s+(\d+)?$/
+ when /^n(?:ext)?(?:\s+(\d+))?$/
if $1
lev = $1.to_i
else
@@ -221,7 +221,7 @@ class DEBUGGER__
STDOUT.printf "no sourcefile available for %s\n", binding_file
end
- when /^up\s+(\d+)?$/
+ when /^up(?:\s+(\d+))?$/
previus_line = nil
if $1
lev = $1.to_i
@@ -237,7 +237,7 @@ class DEBUGGER__
info, binding_file, binding_line = frame_info(frame_pos)
STDOUT.printf "#%d %s\n", frame_pos, info
- when /^down\s+(\d+)?$/
+ when /^down(?:\s+(\d+))?$/
previus_line = nil
if $1
lev = $1.to_i
diff --git a/lib/telnet.rb b/lib/telnet.rb
index 5a0ae40..96e2cac 100644
--- a/lib/telnet.rb
+++ b/lib/telnet.rb
@@ -1,11 +1,11 @@
=begin
-$Date: 1999/07/16 13:39:42 $
+$Date: 1999/08/10 05:20:21 $
== SIMPLE TELNET CLIANT LIBRARY
telnet.rb
-Version 0.231
+Version 0.232
Wakou Aoyama <wakou@fsinet.or.jp>
@@ -34,7 +34,7 @@ the network or the host is very heavy, the value is enlarged.
=== STATUS OUTPUT
- host = Telnet.new({"Hosh" => "localhost"){|c| print c }
+ host = Telnet.new({"Host" => "localhost"){|c| print c }
connection status output.
@@ -147,6 +147,14 @@ of cource, set sync=true or flush is necessary.
== HISTORY
+=== Version 0.232
+
+1999/08/10 05:20:21
+
+- STATUS OUTPUT sample code typo. thanks to Tadayoshi Funaba <tadf@kt.rim.or.jp>
+ host = Telnet.new({"Hosh" => "localhost"){|c| print c }
+ host = Telnet.new({"Host" => "localhost"){|c| print c }
+
=== Version 0.231
1999/07/16 13:39:42
@@ -362,8 +370,8 @@ class Telnet < SimpleDelegator
EOL = CR + LF
v = $-v
$-v = false
- VERSION = "0.231"
- RELEASE_DATE = "$Date: 1999/07/16 13:39:42 $"
+ VERSION = "0.232"
+ RELEASE_DATE = "$Date: 1999/08/10 05:20:21 $"
$-v = v
def initialize(options)