Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8918537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:46:42+00:00 2026-06-15T05:46:42+00:00

I’m trying to validate two date attributes in order that they be consecutive. The

  • 0

I’m trying to validate two date attributes in order that they be consecutive.

The gem validates_timeliness is excellent to validate incorrect dates such as february the 31th.

However I’m trying to make use of :before and :after parameters, but it doesn’t work. It accept a start date of 31 december 2012 while the end date is set to 1st january 2012.

My model :

class Meeting < ActiveRecord::Base
  attr_accessible :date_start, :date_end
  validates :date_start, :date_end, :presence => true

  # Ressource : https://github.com/adzap/validates_timeliness
  validates_date :date_start, :before => :date_end
  validates_date :date_end, :after => :date_start
end

Does validates_timeliness allow to do what I want or isn’t it built for this ?

I would prefer to avoid to use two gems just for handling dates in my app. I mean using validates_timeliness gem with date_validator gem as well.

===== UPDATE =====

There is something that is not working properly with validates_timeless though I can’t find a reason why.
It accepts date_start to be after today even if I set the following validation in my model :

validates_date :date_start, :before => lambda { Date.current }

my /config/initializers/validates_timeliness.rb (for info) :

ValidatesTimeliness.setup do |config|
  # Extend ORM/ODMs for full support (:active_record, :mongoid).
  config.extend_orms = [ :active_record ]

  # Re-display invalid values in date/time selects
  config.enable_date_time_select_extension!

  # Handle multiparameter date/time values strictly
  config.enable_multiparameter_extension!

  # Shorthand date and time symbols for restrictions
  config.restriction_shorthand_symbols.update(
     :now   => lambda { Time.current },
     :today => lambda { Date.current }
   )
  # Use the plugin date/time parser which is stricter and extendable
  config.use_plugin_parser = false
end

Note that if I try to set the date 31th February, I got an error message telling the date is incorrect. I also restart my server each time after a config change.

===== UPDATE 2 =====

I even tried this invalid hash_key, and Rails doesn’t complain :

  validates_date :date_start, :blablabla => lambda { Date.current }

So what’s going on ? what am I doing wrong ?

===== UPDATE 3 =====

It seems to be a bug.
These two options do work :

  validates_date :date_start, :on_or_before => lambda { Date.current }
  validates_date :date_start, :on_or_after => lambda { Date.current }

These two options do NOT work :

  validates_date :date_start, :before => lambda { Date.current }
  validates_date :date_start, :after => lambda { Date.current }

I’m using Rails 3.2.9 and Ruby 1.9.3p194.

Could anybody confirm he has the same issue ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:46:43+00:00Added an answer on June 15, 2026 at 5:46 am

    I haven’t used this gem, but it seems they support lambda’s for the values. Try the following which (should) pass your Meeting instance into the lambda and return the result to the validation method. It has to be done in a lambda since it’s instance specific.

      validates_date :date_start, :before => lambda{|m| m.date_end}
      validates_date :date_end, :after => lambda{|m| m.date_start}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.