2009/6/19 sinker <[email protected]>:
>
> Another weekend-related question:
>
> I have a variable that displays something scheduled for tomorrow.
> Since I'm skipping weekends, on Friday I want it to show what's
> scheduled on Monday.
>
> I know how to get the query right, but I'm not sure about the if
> statement:
>
> Essentially, I need to say if Date.today = friday.... but I can't seem
> to get the syntax right. The rest would simply be:
>
> mystery if statement here
>     �...@tomorrow = Story.find(:first, :conditions => ['rundate =?',
> Date.today+3])
>    else
>     �...@tomorrow = Story.find(:first, :conditions => ['rundate =?',
> Date.today+1])
>    end

Quoting from Rob Biedenharn's earlier post:
> Date#wday gives the "weekday" number: 0=Sunday, 6=Saturday
So the test for friday is
if Date.today.wday == 5

Don't forget to allow for Saturday in your code though.  As it stands
it will set @tomorrow to Sunday if today is Saturday.  I would advise
against calling it @tomorrow if it is not tomorrow, it will confuse
someone sometime. Something like @next_working_day might be better.

Colin

>
> Thanks!!
>
> On Jun 19, 2:11 am, Colin Law <[email protected]> wrote:
>> Here 
>> -http://blog.redfin.com/devblog/2007/08/getting_the_time_zone_from_a_w...
>> - is a way (allegedly) of getting the user's timezone using
>> javascript, which could then be passed to the server.  I cannot vouch
>> for whether it works or not.
>>
>> Colin
>>
>> 2009/6/19 Rick DeNatale <[email protected]>:
>>
>>
>>
>>
>>
>> > On Thu, Jun 18, 2009 at 12:38 PM, Colin Law<[email protected]> wrote:
>>
>> >> 2009/6/18 Rick DeNatale <[email protected]>:
>>
>> >>> You could use
>>
>> >>> Time.zone = current_user.timezone # which would probably be in a 
>> >>> before_filter
>>
>> >> How does current_user.timezone work?
>>
>> > Well there's a little handwaving here. The assumption is that
>> > current_user refers to a user model instance set up by
>> > restful_authentication or some other login code, and that the model
>> > contains the user's preferred timezone probably set by a profile ui.
>>
>> > --
>> > Rick DeNatale
>>
>> > Blog:http://talklikeaduck.denhaven2.com/
>> > Twitter:http://twitter.com/RickDeNatale
>> > WWR:http://www.workingwithrails.com/person/9021-rick-denatale
>> > LinkedIn:http://www.linkedin.com/in/rickdenatale
> >
>

--~--~---------~--~----~------------~-------~--~----~
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