Craig White
2008-Feb-26 17:58 UTC
still trying to coerce numbers and strings for date math
and still going crazy... I have tried everything I can think of...>> interval=> 1>> dinc=> "year">> interval.to_s + "." + dinc=> "1.year">> test = Time.now + (interval.to_s + "." + dinc)TypeError: no implicit conversion to float from string from (irb):263:in `+'' from (irb):263 from :0 crap...that doesn''t work, nor does this...>> (interv.to_s + "." + dinc).to_f=> 1.0 I have to have ''interval'' be a number that I can increment while I test it and ''dinc'' to be the value (i.e., month, year) and reconstitute them. How does one do this? Craig --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Feb-26 18:03 UTC
Re: still trying to coerce numbers and strings for date math
On 26 Feb 2008, at 17:58, Craig White wrote:> > and still going crazy... > > I have tried everything I can think of... > >>> interval > => 1 >>> dinc > => "year" >>> interval.to_s + "." + dinc > => "1.year" >>> test = Time.now + (interval.to_s + "." + dinc) > TypeError: no implicit conversion to float from string > from (irb):263:in `+'' > from (irb):263 > from :0 > > crap...that doesn''t work, nor does this... > >>> (interv.to_s + "." + dinc).to_f > => 1.0 > > I have to have ''interval'' be a number that I can increment while I > test > it and ''dinc'' to be the value (i.e., month, year) and reconstitute > them.I suppose the key here is understanding that year/month etc... are just methods on the integers, so interval = 1 inc = ''year'' test = Time.now + interval.year test = Time.now + interval.send(inc) Fred> How does one do this? > > Craig > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Craig White
2008-Feb-26 18:16 UTC
Re: still trying to coerce numbers and strings for date math
On Tue, 2008-02-26 at 18:03 +0000, Frederick Cheung wrote:> > On 26 Feb 2008, at 17:58, Craig White wrote: > > > > > and still going crazy... > > > > I have tried everything I can think of... > > > >>> interval > > => 1 > >>> dinc > > => "year" > >>> interval.to_s + "." + dinc > > => "1.year" > >>> test = Time.now + (interval.to_s + "." + dinc) > > TypeError: no implicit conversion to float from string > > from (irb):263:in `+'' > > from (irb):263 > > from :0 > > > > crap...that doesn''t work, nor does this... > > > >>> (interv.to_s + "." + dinc).to_f > > => 1.0 > > > > I have to have ''interval'' be a number that I can increment while I > > test > > it and ''dinc'' to be the value (i.e., month, year) and reconstitute > > them. > > I suppose the key here is understanding that year/month etc... are > just methods on the integers, so > interval = 1 > inc = ''year'' > test = Time.now + interval.year > test = Time.now + interval.send(inc)---- bing! Thanks, I don''t know that I would have ever figured this out by myself. Craig --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---