No commit activity in last 3 years
No release in over 3 years
Creates date and time virtual attributes from a date/time attribute
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Date Time Attributes

Creates date and time virtual attributes from a date/time attribute.

Installation

gem install date_time_attribute

Or add it to your Gemfile:

gem 'bootstrap_form_extensions'

Then:

bundle

Usage

class Event < ActiveRecord::Base

  date_time_attributes_for :start_at

end

event = Event.new
event.start_at                    # => nil
                                  
event.start_at = Time.now         # => 2015-10-29 14:59:34 -0400
event.start_date                  # => "2015-10-29"
event.start_time                  # => "18:59:34"
                                  
event.start_date = '1971-10-21'   # => "1971-10-21"
event.start_at                    # => 1971-10-21 14:59:34 -0400
                                  
event.start_time = '11:30:00'     # => "11:30:00"
event.start_at                    # => 1971-10-21 11:30:00 -0400

If the attribute ends with '_at', as in the previous example, the date and time attributes are called attribute_date and attribute_time. Otherwise, 'date' and 'time' just get added to the attribute name:

class Event < ActiveRecord::Base

  date_time_attributes_for :ending

end

event = Event.new
event.ending                      # => nil
                                  
event.ending = Time.now           # => 2015-10-29 14:59:34 -0400
event.ending_date                 # => "2015-10-29"
event.ending_time                 # => "18:59:34"

Plain Ruby Classes

ActiveRecord is extended automatically when the gem is added to a Rails project. If you want to use this in a plain ruby class, just extend the class:

class Event

  extend DateTimeAttributes

  date_time_attributes_for :start_at

end