Why am I not able to do this? x=Time.now y=Time.now + 1.year (x..y).step(1.week) The step function just goes seems to hang in a loop. Shouldn''t it return the remaining weeks in the current year (ignoring the start of week)? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It''s not hanging, it''s stepping through the range. You need to pass it a block to tell it what to do on each step. (x..y).step(1.week) { |x| puts x } Best. Mike On Jul 2, 2008, at 6:59 AM, Mukund wrote:> > Why am I not able to do this? > > x=Time.now > y=Time.now + 1.year > (x..y).step(1.week) > > The step function just goes seems to hang in a loop. Shouldn''t it > return the remaining weeks in the current year (ignoring the start of > week)? > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
In my actual code, I was trying to store the results in an array and it just takes forever. Does it work properly for you? Even if I iterate through the array members using a block, each block takes a *long* time to display something. Ruby --> ruby 1.8.6 (2008-03-03 patchlevel 114) [x86_64-linux] Rails --> Rails 2.1.0 OS --> Fedora 7 x64 I tried this on a fresh rails app as well. Thanks, Mukund On Jul 2, 4:07 pm, Michael Breen <hard...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It''s not hanging, it''s stepping through the range. You need to pass > it a block to tell it what to do on each step. > > (x..y).step(1.week) { |x| puts x } > > Best. > Mike > > On Jul 2, 2008, at 6:59 AM, Mukund wrote: > > > > > Why am I not able to do this? > > > x=Time.now > > y=Time.now + 1.year > > (x..y).step(1.week) > > > The step function just goes seems to hang in a loop. Shouldn''t it > > return the remaining weeks in the current year (ignoring the start of > > week)?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 2 Jul 2008, at 12:25, Mukund wrote:> > In my actual code, I was trying to store the results in an array and > it just takes forever. Does it work properly for you? Even if I > iterate through the array members using a block, each block takes a > *long* time to display something. > > Ruby --> ruby 1.8.6 (2008-03-03 patchlevel 114) [x86_64-linux] > Rails --> Rails 2.1.0 > OS --> Fedora 7 x64 >Not working at all or just very slow? With a non numeric range, ruby calls the succ method as many times as needed per iteration (ie 600000 or so in this case) which could conceivably be slow. You might be better off stepping through a numeric offset that you can add to the origin point, ie (0..1).step(1.week) do |increment| #do something to x.increment end I have an inkling that neither this (not the slow method) will handle dst changes properly as they both force 1.week to an integer. Fred> I tried this on a fresh rails app as well. > > Thanks, > Mukund > > > > On Jul 2, 4:07 pm, Michael Breen <hard...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> It''s not hanging, it''s stepping through the range. You need to pass >> it a block to tell it what to do on each step. >> >> (x..y).step(1.week) { |x| puts x } >> >> Best. >> Mike >> >> On Jul 2, 2008, at 6:59 AM, Mukund wrote: >> >> >> >>> Why am I not able to do this? >> >>> x=Time.now >>> y=Time.now + 1.year >>> (x..y).step(1.week) >> >>> The step function just goes seems to hang in a loop. Shouldn''t it >>> return the remaining weeks in the current year (ignoring the start >>> of >>> week)? > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Just incredibly slow. I ended up doing it the hard/right way but converting time to integer seconds since epoch at the expense of readability. On Jul 2, 4:45 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2 Jul 2008, at 12:25, Mukund wrote: > > > > > In my actual code, I was trying to store the results in an array and > > it just takes forever. Does it work properly for you? Even if I > > iterate through the array members using a block, each block takes a > > *long* time to display something. > > > Ruby --> ruby 1.8.6 (2008-03-03 patchlevel 114) [x86_64-linux] > > Rails --> Rails 2.1.0 > > OS --> Fedora 7 x64 > > Not working at all or just very slow? With a non numeric range, ruby > calls the succ method as many times as needed per iteration (ie 600000 > or so in this case) which could conceivably be slow. You might be > better off stepping through a numeric offset that you can add to the > origin point, ie > > (0..1).step(1.week) do |increment| > #do something to x.increment > end > > I have an inkling that neither this (not the slow method) will handle > dst changes properly as they both force 1.week to an integer. > Fred > > > I tried this on a fresh rails app as well. > > > Thanks, > > Mukund > > > On Jul 2, 4:07 pm, Michael Breen <hard...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> It''s not hanging, it''s stepping through the range. You need to pass > >> it a block to tell it what to do on each step. > > >> (x..y).step(1.week) { |x| puts x } > > >> Best. > >> Mike > > >> On Jul 2, 2008, at 6:59 AM, Mukund wrote: > > >>> Why am I not able to do this? > > >>> x=Time.now > >>> y=Time.now + 1.year > >>> (x..y).step(1.week) > > >>> The step function just goes seems to hang in a loop. Shouldn''t it > >>> return the remaining weeks in the current year (ignoring the start > >>> of > >>> week)?--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---