On Saturday 12 November 2005 10:54 am, Lloyd Zusman wrote:

> Is there any reason for why we can't have similar methods as part of the
> official DateTime and Time classes?
>
> Or is there already some sort of mechanism for this that I have
> overlooked?

You have not overlooked anything.

In my standard set of extensions are these:

class Time
        def to_date
                Date.new(year, month, day)
                rescue NameError
                nil
        end

        def to_datetime
                DateTime.new(year, month, day, hour, min, sec)
                rescue NameError
                nil
        end
end

class DateTime
        def to_time
                Time.local(year,month,day,hour,min,sec)
        end
end

class Date
        def to_time
                Time.local(year,month,day)
        end
end


Kirk Haines