Forum: Ruby on Rails validating a date is a Monday

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
78d56bb0f91c899d40f1767b3040d825?d=identicon&s=25 bingo bob (bingobob)
on 2009-04-10 08:26
I'm trying to do this...

  def validate

     errors.add_to_base "requested start date must be a monday" if
requested_start_date != Chronic.parse('monday')

  end


Not working though - this fails vaildation all the time (regardless of
whether the date is a monday or not)

What am I missing here ?


thanks

bb
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-10 09:31
(Received via mailing list)
On Apr 10, 7:26 am, bingo bob <rails-mailing-l...@andreas-s.net>
wrote:
> whether the date is a monday or not)
>
Chronic.parse('monday') returns a particular monday (looks like next
monday), what else could it do. As a result your code doesn't check
that the day of week is monday, it checks whether it is a particular
monday at a particular time. You should look at the wday method on
Time/Date, which returns the day of week.

Fred
78d56bb0f91c899d40f1767b3040d825?d=identicon&s=25 bingo bob (bingobob)
on 2009-04-10 09:33

I have Chronic in place - can it help me work out if the date is a
Monday?
78d56bb0f91c899d40f1767b3040d825?d=identicon&s=25 bingo bob (bingobob)
on 2009-04-10 09:40
YOU GOT IT :-)... Thanks Fred (again)... easy, no need for chronic..

this seems to work


     errors.add_to_base "requested start date must be a monday" if
requested_start_date.wday != 1


1 being Monday

bb.
This topic is locked and can not be replied to.