{"id":15640528,"url":"https://github.com/nickstenning/validates_date_time","last_synced_at":"2025-08-20T20:31:56.808Z","repository":{"id":417750,"uuid":"37455","full_name":"nickstenning/validates_date_time","owner":"nickstenning","description":"Fork of validates_date_time rails plugin. Please do submit pull requests for any changes, and I'll merge them with Jonathan's svn changes.","archived":false,"fork":false,"pushed_at":"2016-06-18T21:42:13.000Z","size":158,"stargazers_count":72,"open_issues_count":3,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-28T04:24:47.235Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://svn.viney.net.nz/things/rails/plugins/validates_date_time/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nickstenning.png","metadata":{"files":{"readme":"README.markdown","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2008-07-26T16:04:54.000Z","updated_at":"2025-04-04T14:51:18.000Z","dependencies_parsed_at":"2022-07-07T18:12:16.442Z","dependency_job_id":null,"html_url":"https://github.com/nickstenning/validates_date_time","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/nickstenning/validates_date_time","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickstenning%2Fvalidates_date_time","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickstenning%2Fvalidates_date_time/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickstenning%2Fvalidates_date_time/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickstenning%2Fvalidates_date_time/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nickstenning","download_url":"https://codeload.github.com/nickstenning/validates_date_time/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickstenning%2Fvalidates_date_time/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271378680,"owners_count":24749192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T11:36:56.906Z","updated_at":"2025-08-20T20:31:56.417Z","avatar_url":"https://github.com/nickstenning.png","language":"Ruby","funding_links":["http://www.paypal.com/cgi-bin/webscr?cmd=_send-money)!"],"categories":[],"sub_categories":[],"readme":"validates_date_time\r\n===================\r\nThis plugin adds the ability to do stricter date and time checking with ActiveRecord.\r\n\r\nThis fork is patched to work with Rails 3.0.\r\n\r\nInstall\r\n=======\r\n\r\nPut this in your Gemfile:\r\n\r\n```ruby\r\ngem \"validates_date_time\", :git =\u003e \"git://github.com/sofatutor/validates_date_time\", :branch =\u003e 'rails-3'\r\n```\r\n\r\nInstructions\r\n============\r\nThe validators can be used to parse strings into Date and Time objects as well as restrict  \r\nan attribute based on other dates or times.\r\n\r\n    class Person \u003c ActiveRecord::Base\r\n      validates_date     :date_of_birth\r\n      validates_time     :time_of_birth\r\n      validates_date_time :date_and_time_of_birth\r\n    end\r\n  \r\nUse `:allow_nil` to allow the value to be blank.\r\n\r\n    class Person \u003c ActiveRecord::Base\r\n      validates_date :date_of_birth, :allow_nil =\u003e true\r\n    end\r\n  \r\nSupported formats\r\n=================\r\nThe default for the plugin is to expect dates in day/month/year format. If you are in the\r\nUS, you will want to change the default to month/day/year by placing the following in `config/environment.rb`\r\n\r\n    ValidatesDateTime.us_date_format = true\r\n  \r\nDate format examples:\r\n - 2006-01-01\r\n - 1 Jan 06\r\n - 1 Jan 2006\r\n - 10/1/06\r\n - 1/1/2006\r\n  \r\nTime format examples:\r\n - 1pm\r\n - 10:11\r\n - 12:30pm\r\n - 8am\r\n\r\nDatetime format examples:\r\n - 1 Jan 2006 2pm\r\n - 31/1/06 8:30am\r\n\r\nExamples\r\n========\r\nIf an attribute value can not be parsed correctly, an error is added: \r\n\r\n    p = Person.new\r\n    p.date_of_birth = \"1 Jan 2006\"\r\n    p.time_of_birth = \"5am\"\r\n    p.save # true\r\n\r\n    p.date_of_birth = \"30 Feb 2006\"\r\n    p.save # false, 30 feb is invalid for obvious reasons\r\n\r\n    p.date_of_birth = \"java is better than ruby\"\r\n    p.save # false\r\n  \r\nIn the final example, as I'm sure you are aware, the record failed to save not only\r\nbecause \"java is better than ruby\" is an invalid date, but more importantly, because the statement is blatantly false. ;) \r\n\r\nRestricting date and time ranges\r\n================================\r\nUsing the `:before` and `:after` options you can restrict a date or time value based on other attribute values  \r\nand predefined values. You can pass as many value to `:before` or `:after` as you like.\r\n\r\n    class Person\r\n      validates_date :date_of_birth, :before =\u003e [:date_of_death, Proc.new { 1.day.from_now_to_date}], :after =\u003e '1 Jan 1900'\r\n      validates_date :date_of_death, :before =\u003e Proc.new { 1.day.from_now.to_date }\r\n    end\r\n  \r\n    p = Person.new\r\n    p.date_of_birth = '1800-01-01'\r\n    p.save  # false\r\n    p.errors[:date_of_birth] # must be after 1 Jan 1900\r\n\r\n    p.date_of_death = Date.new(2010, 1, 1)\r\n    p.save  # false\r\n    p.errors[:date_of_death] # must be before \u003c1 day from now\u003e\r\n\r\n    p.date_of_birth = '1960-03-02'\r\n    p.date_of_death = '2003-06-07'\r\n    p.save  # true\r\n  \r\nYou can customise the error messages for dates or times that fall outside the required range. The boundary date will be substituted in for %s. Eg:\r\n\r\n    class Person\r\n      validates_date :date_of_birth, :after =\u003e Date.new(1900, 1, 1), :before =\u003e Proc.new { 1.day.from_now.to_date }, :before_message =\u003e 'Ensure it is before %s', :after_message =\u003e 'Ensure it is after %s'\r\n    end\r\n\r\nAuthor\r\n======\r\nIf you find this plugin useful, please consider a donation to [show your support](http://www.paypal.com/cgi-bin/webscr?cmd=_send-money)!\r\nSuggestions, comments, problems are all welcome. You'll find me at jonathan.viney@gmail.com\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickstenning%2Fvalidates_date_time","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnickstenning%2Fvalidates_date_time","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickstenning%2Fvalidates_date_time/lists"}