On 10/24/06, Chris Richards <evilgeenius / gmail.com> wrote:
>
> The Time::next_week method is supposed to give the time of the start of
> the next week.  But  look at this, it cocks up :
>
> >> t=Time.parse "Monday October 16th 2006"
> => Mon Oct 16 00:00:00 BST 2006
> >> t.next_week
> => Mon Oct 23 00:00:00 BST 2006
> >> t.next_week.next_week
> => Tue Oct 24 00:00:00 BST 2006
> >> t.next_week.next_week.next_week
> => Mon Oct 30 00:00:00 GMT 2006

I agree with everyone else that your manners while pleading for help
could use some work.  I empathize, however, with screwed up data and
how that can put you in a bad mood. That said...

This is really not as widespread a bug as it looked to me when you
first mentioned it, but is  an edge case tied to the messed up system
we have called "Daylight Savings Time". What's happening is that the
next week function hops forward by 7 days, then pulls back to the
Monday immediately preceding (or coinciding with) the resulting date.
This usually works all fine and handy. But if:

 * the seven day jump crosses the DST boundary
 * the seven day jump ends on a Monday, and
 * the time portion is within an hour of midnight

Then the timezone change is going to change early Monday morning to
late Sunday night, and next_week will slurp it back 6 days to what it
thinks is the previous Monday. But since we cross the boundary again,
we actually make it back to Tuesday. The second time you call
next_week (from Tuesday), we don't end on Monday, so there's no
problem (aside from the wrong starting point).

Similar conditions will apply in April where if you start late Sunday
night the Sunday before DST, the Monday 8 days in the future (instead
of 1 day) will be returned. Stupid Daylight Savings Time. As if it
doesn't confuse us humans enough, it has to go and mess with our code.

FWIW, this issue has actually been brought up on the Rails list and a
patch submitted[1], all the way back in June. Now just to see if that
patch can gain some momentum in actually being committed...

Jacob Fugal

[1] http://dev.rubyonrails.org/ticket/5617