On Dec 8, 2008, at 10:55 AM, Matt Darby wrote:

>
> I have a "timesheet" in my app that simply displays the week range
> based on a passed in date (params[:date]).
> The view iterates through the Date::ABBR_DAYNAMES and shows a link to
> the corresponding date.

What do you pass to get_work_week_date_range?  Is it a string?  Or an  
instance of Date?  Or Time?

If it worked once it should always work.  Which suggests that maybe  
you're passing in something different from time to time?  One time a  
Date, one time a Time?

Maybe?

Put together a test and explicitly pass the *same* argument (class and  
value) and see if you can duplicate it.



> Trouble is that about 40% of the time the calculated dates go bonkers.
> Am I missing something?
>
> Model:
>  # Get a date range of the week that a particular date falls in
>  # This is broken out like mad for diagnostics
>  def self.get_work_week_date_range(date)
>    monday   = date.monday
>    sunday   = monday - 1.day
>    eow      = date.end_of_week
>    saturday = eow - 1.day
>
>    dates = [sunday, saturday]
>
>    logger.info
> (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
>    logger.info(">>>>> #{date}.monday = #{monday}")
>    logger.info(">>>>> #{monday}-1.day = #{sunday}")
>    logger.info(">>>>> #{date}.end_of_week = #{eow}")
>    logger.info(">>>>> #{eow}-1.day = #{saturday}")
>    logger.info(">>>>> #{date} == [#{dates[0]}, #{dates[1]}]")
>    logger.info
> (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
>
>    dates
>  end
>
> Logger output:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>> 2008-12-08.monday = 2008-12-08
>>>>>> 2008-12-08-1.day = 2008-12-07
>>>>>> 2008-12-08.end_of_week = 2008-12-14
>>>>>> 2008-12-14-1.day = 2008-12-13
>>>>>> 2008-12-08 == [2008-12-07, 2008-12-13]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>
> ... n times later ...
>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>> 2008-12-08.monday = 2008-12-08
>>>>>> 2008-12-08-1.day = 1772-05-19
>>>>>> 2008-12-08.end_of_week = 3428-04-08
>>>>>> 3428-04-08-1.day = 3191-09-18
>>>>>> 2008-12-08 == [1772-05-19, 3191-09-18]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> >


--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to