Infinite Time

rubyists-

anyone know of a way to get at infinite times (if they exist) as one can for
Floats?

eg.

irb(main):001:0> 1.0/0
=> Infinity

but for Time objects.

-a

···

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

Hi,

···

In message “infinite Time” on 03/03/21, ahoward ahoward@fsl.noaa.gov writes:

anyone know of a way to get at infinite times (if they exist) as one can for
Floats?

Unfortunately, Time is a limited resource. We cannot have times
further than 2038-01-19 on most platforms.

						matz.

totally OT, but I’d even love to see
a=1.0
b=0
(a/b).times {bloc}

instread of
while true

:slight_smile:

···

il Fri, 21 Mar 2003 06:49:23 +0000, ahoward ahoward@fsl.noaa.gov ha scritto::

rubyists-

anyone know of a way to get at infinite times (if they exist) as one can for
Floats?

Maybe this approach helps:

class TimeInfinity
include Comparable

def <=>(o)
if o.kind_of? Time then
1
elsif o.kind_of? TimeInfinity then
0
else
-1
end
end

def to_s() “Infinity”; end
end

class Time
alias compare <=>

def <=>(o)
o.kind_of?( TimeInfinity ) ? (0-(o<=>self)) : compare(o)
end
end

times=[Time.now, TimeInfinity.new, Time.now]

puts times.join ", "
puts times.sort.join ", "

“Yukihiro Matsumoto” matz@ruby-lang.org schrieb im Newsbeitrag
news:1048255598.253957.30111.nullmailer@picachu.netlab.jp…

Hi,

anyone know of a way to get at infinite times (if they exist) as one
can for

···

In message “infinite Time” > on 03/03/21, ahoward ahoward@fsl.noaa.gov writes:

Floats?

Unfortunately, Time is a limited resource. We cannot have times
further than 2038-01-19 on most platforms.

matz.

i would very much like to see a few time constants, such as

Time::NEGATIVE_INFINITY # perhaps alias NI
Time::EPOCH # perhaps alias E
Time::INFINITY # perhaps alias I

included in the Time class.

postgresql has these facilities and they are very usefull :

entry = {
:answer => 42,
:valid_begin => Time::NI,
:valid_end => Time::I,
}

which states that ‘the answer has been 42 from the beginning of time, and will
remain thus untill the end of time’

Time::NI has the property that

Time::NI < all other times except Time::NI

it can be thought of as being ‘the beginning of time’

and

Time::I has the property that

Time::I > all other times except Time::I

it can be thought of as ‘the end of time’ or ‘forever’

my 2c.

-a

···

On Fri, 21 Mar 2003, Yukihiro Matsumoto wrote:

Hi,

In message “infinite Time” > on 03/03/21, ahoward ahoward@fsl.noaa.gov writes:

anyone know of a way to get at infinite times (if they exist) as one can for
Floats?

Unfortunately, Time is a limited resource. We cannot have times
further than 2038-01-19 on most platforms.

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

thanks, this is exactly what i have done. i would really like to see this
sort of thing built into the Time class, as Float::Infinity has been built
into the Float class.

-a

···

On Fri, 21 Mar 2003, Robert Klemme wrote:

Maybe this approach helps:

====================================
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

if Time::now == Time::INFINITY
raise ApocalypticException,
“Gee whiz. You coded in Ruby until the end, didn’t you?”
end

···

On Friday 21 March 2003 09:22 am, ahoward wrote:

Time::NI has the property that

Time::NI < all other times except Time::NI

it can be thought of as being ‘the beginning of time’

and

Time::I has the property that

Time::I > all other times except Time::I

it can be thought of as ‘the end of time’ or ‘forever’

Hi,

···

At Sat, 22 Mar 2003 01:22:49 +0900, ahoward wrote:

i would very much like to see a few time constants, such as

Time::NEGATIVE_INFINITY # perhaps alias NI
Time::EPOCH # perhaps alias E
Time::INFINITY # perhaps alias I

included in the Time class.

class Time
NEGATIVE_INFINITY = -1.0 / 0
INFINITY = 1.0 / 0
EPOCH = 0
end


Nobu Nakada

looks promising. however, can anyone explain why this approach to
implementing the comparisions does not work???

class Time
INF = INFINITY = 1.0 / 0
NINF = NEGATIVE_INFINITY = -1.0 / 0
EPOCH = Time.at(0)

class << INFINITY
  include Comparable
  def <=> o;self.id == o.id ? 0 : 1;end
end

class << NEGATIVE_INFINITY
  include Comparable
  def <=> o;self.id == o.id ? 0 : -1;end
end

end

def display command
puts “#{command}”
puts “\t# >> #{eval command}”
end

display %Q(Time::INF <=> Time::NINF)
display %Q(Time::NINF <=> Time::INF)

display %Q(Time.now <=> Time::INF)
display %Q(Time::INF <=> Time.now)

display %Q(Time.now <=> Time::NINF)
display %Q(Time::NINF <=> Time.now)

why does this raise an exception??

display %Q(Time::INF > Time.now)

i could use singleton objects for INF and NINF, but would like to avoid that.

i am unclear as to why

class << object
include Comparable
def <=> …
end

does NOT, in this case, seem to redefine the ‘>’ operator.

i swear, every time i think i understand this bloody ‘class << self’
business…

i thought the above would (re)define all the comparison operators for the
singleton class of INF…

-a

···

On Sat, 22 Mar 2003 nobu.nokada@softhome.net wrote:

class Time
NEGATIVE_INFINITY = -1.0 / 0
INFINITY = 1.0 / 0
EPOCH = 0
end

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

Hi,

class Time
NEGATIVE_INFINITY = -1.0 / 0
INFINITY = 1.0 / 0
EPOCH = 0
end

looks promising. however, can anyone explain why this approach to
implementing the comparisions does not work???

You need to coerce.

class Time
def coerce(x)
case x
when Float
return [x, to_f]
when Integer
return [x, to_i]
else
super
end
end

INF   = INFINITY          =  1.0 / 0
NINF  = NEGATIVE_INFINITY = -1.0 / 0
EPOCH = Time.at(0)

end

i am unclear as to why

class << object
include Comparable
def <=> …
end

does NOT, in this case, seem to redefine the ‘>’ operator.

Float#> doesn’t call <=> due to performance.

···

At Sat, 22 Mar 2003 03:44:31 +0900, ahoward wrote:

On Sat, 22 Mar 2003 nobu.nokada@softhome.net wrote:


Nobu Nakada

You need to coerce.

thanks! didn’t know Time.coerce existed…

Float#> doesn’t call <=> due to performance.

but

class << INF
include Comparable

end

should create a ‘>’ correct?

anyhow, this seems to work fine :

----CUT----
class Time
INF = INFINITY = 1.0 / 0
NINF = NEGATIVE_INFINITY = -1.0 / 0
EPOCH = Time.at(0)

class << INFINITY
  include Comparable
  def <=> o;id == o.id ? 0 : 1;end
end

class << NEGATIVE_INFINITY
  include Comparable
  def <=> o;self.id == o.id ? 0 : -1;end
end

def coerce(x)
  case x
  when Float
return [x, to_f]
  when Integer
return [x, to_i]
  else
super
  end
end

end

a test

def display command
puts “\t#{command}”
puts “\t\t# >> #{eval command}”
end

$now = Time.now
objects = %w(Time::INF Time::NINF $now)

objects.map do |a|
puts ‘========’
objects.map do |b|
puts “\t--------”
%w(<=> <= >= < > ==).map do |op|
display “#{a} #{op} #{b}”
end
end
end
----CUT----

-a

···

On Sat, 22 Mar 2003 nobu.nokada@softhome.net wrote:

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

Hi,

You need to coerce.

thanks! didn’t know Time.coerce existed…

No, you need to define it because it doesn’t exist.

Float#> doesn’t call <=> due to performance.

but

class << INF
include Comparable

end

should create a ‘>’ correct?

Currently, it doesn’t because of performance cost.

class << INFINITY
  include Comparable
  def <=> o;id == o.id ? 0 : 1;end
end

class << NEGATIVE_INFINITY
  include Comparable
  def <=> o;self.id == o.id ? 0 : -1;end
end

I guess these singletons are unnecessary, since Float already
includes Comparable and infinities return correct comparison.

···

At Sat, 22 Mar 2003 05:04:59 +0900, ahoward wrote:


Nobu Nakada