Flex Date integration for rails

gem install flex_date_rails -v 0.2.2


FlexDate integration for Rails.

Flexible dates for Rails/ActiveRecord, as a gem. Originally written by Alex Reisner, packaged as a gem. github.com/alexreisner/flex_date

Use with Bundler

Add the following to your Gemfile.

gem 'flex_date_rails', '0.2.2'

And create an intializer in config/intializers/flex_date.rb

require 'flex_date_rails'

Integration with Rails/ActiveRecord

The MultipartDate module facilitates integration of FlexDate with ActiveRecord models. It requires that you store each date in three separate columns, each with a _y, _m, or _d suffix. So, if you have a Person model that stores birthdays, the columns required would be (all integers):


Then, simply put this in your Person model (you can list multiple attributes if needed):

multipart_date :birthday

and you'll be able to do things like this:

# Initialize a new Person object (don't know year they were born).
p = Person.new(:birthday_m => 8, :birthday_d => 23)

# See if their birthday is set.
  => true

# Get their birthday as a FlexDate object.
b = p.birthday
  => #<FlexDate:0xb78b542c ...>

# Display their birthday nicely.
  => "August 23"

# Add the year when you find out.
p.birthday_y = 1964
  => "August 23, 1964"

To-do List

  • MultipartDate::multipart_date should also generate a setter method.

Released under the MIT license.