[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

DateTime is not a Date?

Sammy Larbi

11/19/2006 11:16:00 PM

So, I was playing around a little in Ruby and noticed that |DateTime| is
a subclass of |Date|, yet the method |today| is not defined for it.

I can certainly see how it doesn't make sense to have that method for
that class, but I'm wondering why a Date isn't a DateTime? I suppose
then we'd be removing the time element, so we'd get the same problem...
but it was just striking is all.



3 Answers

Scott

11/20/2006 3:48:00 AM

0

It seems that on line 1261 of date.rb (inside the DateTime class), the
'today' method is undefined. For more information on Date, DateTime,
and Time, you may want to check out Sam Smoot's article on the subject:
http://substantiality.net/articles/2006/10/16/date-time-and-dateti...


-Scott

Sammy Larbi wrote:
> So, I was playing around a little in Ruby and noticed that |DateTime| is
> a subclass of |Date|, yet the method |today| is not defined for it.
>
> I can certainly see how it doesn't make sense to have that method for
> that class, but I'm wondering why a Date isn't a DateTime? I suppose
> then we'd be removing the time element, so we'd get the same problem...
> but it was just striking is all.

Robert Klemme

11/20/2006 10:58:00 AM

0

On 20.11.2006 00:16, Sammy Larbi wrote:
> So, I was playing around a little in Ruby and noticed that |DateTime| is
> a subclass of |Date|, yet the method |today| is not defined for it.

First of all this method is a singleton method of instance Date and
these are not inherited the same way as instance methods are.
DateTime.today does not make much sense - after all, what time would you
expect? Instead there is DateTime.now:

>> Date.methods - DateTime.methods
=> ["today"]
>> DateTime.methods - Date.methods
=> ["now", "valid_time?"]

> I can certainly see how it doesn't make sense to have that method for
> that class, but I'm wondering why a Date isn't a DateTime? I suppose
> then we'd be removing the time element, so we'd get the same problem...
> but it was just striking is all.

A Date cannot be a DateTime because it lacks time. Consequently
DateTime inherits Date:

>> Date.ancestors
=> [Date, Comparable, Object, Kernel]
>> DateTime.ancestors
=> [DateTime, Date, Comparable, Object, Kernel]

Once can certainly argue whether DateTime *is a* Date or rather *has a*
Date. But it is definitively clear that Date *is not* a DateTime simply
because it does not provide the same set of information that DateTime
provides (date *and* time).

Kind regards

robert

Sammy Larbi

11/20/2006 12:45:00 PM

0

Scott wrote, On 11/19/2006 9:50 PM:
> It seems that on line 1261 of date.rb (inside the DateTime class), the
> 'today' method is undefined. For more information on Date, DateTime,
> and Time, you may want to check out Sam Smoot's article on the subject:
> http://substantiality.net/articles/2006/10/16/date-time-and-dateti...
>
>
>

Thanks for that link... Someone else brought that line to my attention
as well.

> -Scott
>
> Sammy Larbi wrote:
>
>> So, I was playing around a little in Ruby and noticed that |DateTime| is
>> a subclass of |Date|, yet the method |today| is not defined for it.
>>
>> I can certainly see how it doesn't make sense to have that method for
>> that class, but I'm wondering why a Date isn't a DateTime? I suppose
>> then we'd be removing the time element, so we'd get the same problem...
>> but it was just striking is all.
>>
>
>
>
>
>