From: Jim Cropcho Date: 2008-01-24T11:45:02+09:00 Subject: Re: [PATCH] Friendlier methods to compare two Time objects ------=_Part_26230_7704839.1201142705581 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Content-Disposition: inline A new thought: > The way that the <=> method is rewritten for Time, it is > optimized (as far as I can tell) to evaluate conditions > based on nanoseconds only when equality cannot be > determined via seconds. I may be misreading that. > > Conversely, Time inherits its > and < methods from its superclass, > so surely those optimizations in <=> do not exist, and creating > aliases would yield less-optimized code. Also, in the other classes > where I add this functionality, current techniques to optimize > comparisons will be reimplemented using the local methodology. from the rdoc for compar.c: The Comparable mixin is used by classes whose objects may be ordered. The class must define the <=>operator, which compares the receiver against another object, returning -1, 0, or +1 depending on whether the receiver is less than, equal to, or greater than the other object. Comparableuses <=> to implement the conventional comparison operators (<, <=, ==, >=, and >) and the method between? . I am now writing a Mixin called Temporal which will be included in the Time , Date and DateTime classes, and will contain the instance methods *before?(some_time) *after?(some_time) *future?(time = Time.now) *past?(time = Time.now) I have the tests written and skeleton code to compile and include the module where necessary. I hope to be finished tomorrow. 2008/1/23 Mathieu Blondel < mblondel@rubyforge.org >: > Hi, > > 2008/1/23, Martin Duerst < duerst@it.aoyama.ac.jp>: > > > There is even some cultural dependency here. In Japanese, for example, > > the past is higher than the future, time flows down, > > And in Chinese as well. For example: > > 下个星期 = next week, lit. below week > 上个星期 = last week, lit. above week > > > Mathieu > > ------=_Part_26230_7704839.1201142705581 Content-Type: text/html; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Content-Disposition: inline A new thought:

> The way that the <=> method is rewritten for Time, it is
> optimized (as far as I can tell) to evaluate conditions
> based on nanoseconds only when equality cannot be
> determined via seconds. I may be misreading that.
>
> Conversely, Time inherits its > and < methods from its superclass,
> so surely those optimizations in <=> do not exist, and creating
> aliases would yield less-optimized code. Also, in the other classes
> where I add this functionality, current techniques to optimize
> comparisons will be reimplemented using the local methodology.

from the rdoc for compar.c:

The Comparable mixin is used by classes whose objects may be ordered. The class must define the <=> operator, which compares the receiver against another object, returning -1, 0, or +1 depending on whether the receiver is less than, equal to, or greater than the other object. Comparable uses <=> to implement the conventional comparison operators (<, <=, ==, >=, and >) and the method between?.

I am now writing a Mixin called Temporal which will be included in the Time , Date and DateTime classes, and will contain the instance methods

*before?(some_time)
*after?(some_time)
*future?(time = Time.now)
*past?(time = Time.now)

I have the tests written and skeleton code to compile and include the module where necessary. I hope to be finished tomorrow.

2008/1/23 Mathieu Blondel < mblondel@rubyforge.org >:
Hi,

2008/1/23, Martin Duerst < duerst@it.aoyama.ac.jp>:

> There is even some cultural dependency here. In Japanese, for example,
> the past is higher than the future, time flows down,

And in Chinese as well. For example:

下个星期 = next week, lit. below week
上个星期 = last week, lit. above week


Mathieu


------=_Part_26230_7704839.1201142705581--