Thanks all. I think to problem with the first one is actually
a bug (would explain why it works in edge), and with the second
one was as John pointed out me trying to use "==" instead of "==="
to check equality between two object.
Thanks!
-glenn
Bradly wrote:
> Are you in Rails or straight Ruby? Rails to_s from dates is different
> from Ruby's. Actually it looks like you are in Rails because
> .to_datetime is part of ActiveSupport.
>
> Your first attempt works for me using edge rails. It could be you have a
> default date/time format that to_datetime isn't able to parse. What does
> d.to_s return? I get "09/22/2008". Have you changed the default
> formatter in your initializers maybe?
>
> Hope that helps.
>
> -Brad
>
>
> On Mon, Sep 22, 2008 at 3:32 PM, Glenn Little <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> wrote:
>
>
> I'm not figuring out how to convert a Time or DateTime into
> a string, and then back into an equivalent object. Initial
> attempts were the obvious:
>
> >> d = DateTime.now
> => Mon, 22 Sep 2008 15:29:05 -0700
> >> d == d.to_s.to_datetime <-- "should" return true
> => false
> >> d.to_s.to_datetime.to_s
> => "2008-09-22T15:29:05+00:00"
>
>
> So then I tried using the parse() methods:
>
> >> d = DateTime.now
> => Mon, 22 Sep 2008 15:22:07 -0700
> >> d == DateTime.parse(d.to_s) <-- "should" return true
> => false
> >> d
> => Mon, 22 Sep 2008 15:22:07 -0700
> >> DateTime.parse(d.to_s)
> => Mon, 22 Sep 2008 15:22:07 -0700
> >> d.to_s
> => "2008-09-22T15:22:07-07:00"
> >> DateTime.parse(d.to_s).to_s
> => "2008-09-22T15:22:07-07:00"
> >> d.to_s == DateTime.parse(d.to_s).to_s
> => true
>
> Does anyone see what I'm doing wrong?
>
> Thanks!
>
> -glenn
>
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---