Time class changed in ruby-1.8.6?

Hi guys. I’m in the process of migrating a ruby app from 1.8.5 to 1.8.6
and noticed that the Time class seems to have changed. It used to have a
convenient to_date method, but is now lacking it, and I’ve had little
luck trying to find the release notes indicating why this changed. Can
anyone point in that direction and/or suggest a better way of converting
times to dates? Merci.

  • donald

On Aug 22, 2007, at 3:10 PM, Ball, Donald A Jr (Library) wrote:

Hi guys. I’m in the process of migrating a ruby app from 1.8.5 to
1.8.6
and noticed that the Time class seems to have changed. It used to
have a
convenient to_date method, but is now lacking it, and I’ve had little
luck trying to find the release notes indicating why this changed.

I don’t ever remember such a method in Ruby. Rails adds a to_date()
method to Time though. Could that be what you are thinking of?

James Edward G. II

thinking of?
It could very well be, my apologies, I’ll poke through the rails
changelogs. Thanks.

  • donald

Ball, Donald A Jr (Library) wrote:

Hi guys. I’m in the process of migrating a ruby app from 1.8.5 to 1.8.6
and noticed that the Time class seems to have changed.

I think the whole date implemetation was substituted by a new
implementation (date2), which isn’t fully compatible to the old one. Now
Time#to_date, which is mixed in from file date.rb, is a private method.
You could send :to_date to your Time object. I have now idea why it
is private now. Why aren’t all three to_* methods defined in all Time,
Date, and DateTime classes? This would make converting between different
time objects much easier.

Daniel DeLorme wrote:

You’re probably using rails.

No, I am not. Maybe Mr. Ball did. I didn’t remember, if there already
where any of those methods before, but I have implemented my own set of
to_* methods to convert between the different objects a while ago. Of
course there also had to be solutions to convert a DateTime to a Time
object, if the latter is not valid, e.g. before the epoch, or a Date
object to a Time object: which time will it show?

It still doesn’t make sense to not have any way to convert between the
three types of objects (short of using #parse/the ugly long
constructors) or have only a part of them as private methods. And why
are the objects immutable? And if they have to be immutable, why is it
so difficult to create a new object from the old, that shows 13:13:13
instead of 23:13:42 without adding the exact amount of seconds to it or
use constructors/parse?

Ruby used to not have a Time#to_date
method but now it has one which is private. And the to_date helper added
by rails is further up the call chain and therefore gets hidden by the
private method, so that’s what you get. :-/

Add one of the following in your environment.rb:
class Time; public :to_date ;end #use the ruby-1.8.6 version
class Time; remove_method :to_date ;end #use the rails version

I think Ruby without Rails should also be able to handle dates and times
well. When I implemented those methods myself, I wondered if anyone uses
all these classes at all, because so much was missing to make them
useful. And if everybody keeps monkey patching the missing methods, it’s
no wonder, that things break, if the standard library changes again.

To create a good API for these timely things seems to be difficult: Java
for example trys it for the second time: its Calendar API is very, very
powerful but it still sucks, especially for the simple things.

Florian F. wrote:

time objects much easier.
You’re probably using rails. Ruby used to not have a Time#to_date
method but now it has one which is private. And the to_date helper added
by rails is further up the call chain and therefore gets hidden by the
private method, so that’s what you get. :-/

Add one of the following in your environment.rb:
class Time; public :to_date ;end #use the ruby-1.8.6 version
class Time; remove_method :to_date ;end #use the rails version

Daniel

Florian F. wrote:

Daniel DeLorme wrote:

You’re probably using rails.

No, I am not. Maybe Mr. Ball did.

Of course, I meant the OP

I think Ruby without Rails should also be able to handle dates and times
well. When I implemented those methods myself, I wondered if anyone uses
all these classes at all, because so much was missing to make them
useful. And if everybody keeps monkey patching the missing methods, it’s
no wonder, that things break, if the standard library changes again.

100% agree. In addition to date/time conversion I’ve also found it
annoyingly difficult and clunky to work with multiple timezones.
Date/time classes should be 1st-class citizens of the ruby core but
instead they are relegated to the stdlib or 3rd-party libraries. I dream
of the day when we could have automatic Time <=> DateTime conversion
(like Fixnum <=> Bignum) and natural timezone handling. I love how ruby
makes everything seem effortless and natural, but date/time handling is
unfortunately a sore spot. :-/

Daniel

On Sunday 02 September 2007 08:28:45 am Matthew R. wrote:

I think I’ve found another change.

Time.now.strftime("%d %h '%y")
=> “”

Time.now.strftime("%d %b '%y")
=> “02 Sep '07”

ie. seemingly support for “%h” has been removed.

It hasn’t been here.

irb(main):001:0> Time.now.strftime("%h")
=> “Sep”
irb(main):002:0> RUBY_VERSION
=> “1.8.6”

Konrad M. wrote:

It hasn’t been here.

irb(main):001:0> Time.now.strftime("%h")
=> “Sep”
irb(main):002:0> RUBY_VERSION
=> “1.8.6”

:-S
That’s annoying.
If only I didn’t use windows :slight_smile:

Ball, Donald A Jr (Library) wrote:

Hi guys. I’m in the process of migrating a ruby app from 1.8.5 to 1.8.6
and noticed that the Time class seems to have changed. It used to have a
convenient to_date method, but is now lacking it, and I’ve had little
luck trying to find the release notes indicating why this changed. Can
anyone point in that direction and/or suggest a better way of converting
times to dates? Merci.

  • donald

I think I’ve found another change.
I don’t know if this is on purpose.

But at some point before ruby 1.8.6 the following code worked;

Time.now.strftime("%d %h '%y")
=> “02 Sep '07”

Time.now.strftime("%d %b '%y")
=> “02 Sep '07”

But now in 1.8.6;

Time.now.strftime("%d %h '%y")
=> “”

Time.now.strftime("%d %b '%y")
=> “02 Sep '07”

ie. seemingly support for “%h” has been removed.

2007/9/2, Matthew R. [email protected]:

That’s annoying.
If only I didn’t use windows :slight_smile:


Posted via http://www.ruby-forum.com/.

I suggest to use “ri” and check out comments - maybe you’ll find
something
useful informations about update 1.8.5-1.8.6 and changes in this class.
Check it out!

Yours,
Killavus.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs