DateTime Enumerator

26 views
Skip to first unread message

Colin Law

unread,
Sep 26, 2015, 12:04:59 PM9/26/15
to Ruby on Rails: Talk
Can someone explain this for me please?

range = (DateTime.now..DateTime.now+1.hour).step(10.minute)
=> #<Enumerator: Sat, 26 Sep 2015 16:41:18 +0100..Sat, 26 Sep 2015
17:41:18 +0100:step(600 seconds)>
2.1.3 :009 > range.to_a
=> [Sat, 26 Sep 2015 16:41:18 +0100]

Not what I expected at all.

Colin

Jim Ruther Nill

unread,
Sep 26, 2015, 2:30:24 PM9/26/15
to rubyonra...@googlegroups.com


Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsXVDpNezdm0V3EJKh_XRhD6hdD1Bb%3DAJ4k2a2SoEqfjA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
-------------------------------------------------------------
visit my blog at http://www.jimruthernill.com

Colin Law

unread,
Sep 26, 2015, 4:43:08 PM9/26/15
to Ruby on Rails: Talk
On 26 September 2015 at 19:29, Jim Ruther Nill <jvn...@gmail.com> wrote:
> hmm maybe relevant
> http://www.benknowscode.com/2014/02/ruby-date-time-range-intervals.html

Thanks, if I interpret that correctly it is saying that what I am
trying to do just doesn't work, that it is a limitation of ruby. It
is not a big problem as there are other simple ways of achieving the
desired result.

Colin
> https://groups.google.com/d/msgid/rubyonrails-talk/CAJ8y7VdPOMAd13Ct83sKaqkFmw_xbsU-9CMNX67KsvZSJtZsdA%40mail.gmail.com.

Jim Ruther Nill

unread,
Sep 26, 2015, 9:41:59 PM9/26/15
to rubyonra...@googlegroups.com
On Sun, Sep 27, 2015 at 4:41 AM, Colin Law <cla...@gmail.com> wrote:
On 26 September 2015 at 19:29, Jim Ruther Nill <jvn...@gmail.com> wrote:
> hmm maybe relevant
> http://www.benknowscode.com/2014/02/ruby-date-time-range-intervals.html

Thanks, if I interpret that correctly it is saying that what I am
trying to do just doesn't work, that it is a limitation of ruby.  It
is not a big problem as there are other simple ways of achieving the
desired result.

Yeah looks like it.  I vaguely remember encountering something like this before
but I can't quite put my finger on what I needed back then.  If you find a way to
make it work using the step method, share it here :D
 

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages