From: Lloyd Zusman Date: 2005-11-14T01:07:26+09:00 Subject: Re: Converting between Time and DateTime Kirk Haines writes: > 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. Oh well ... (sigh) And thanks. In your methods below, I see "rescue" without a formal "begin/end" block. I've never seen that construct before. I'm guessing that single line statements don't need begin/end, correct? > 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 > > -- Lloyd Zusman ljz@asfast.com God bless you.