Project

smart_time

0.0
No commit activity in last 3 years
No release in over 3 years
Leverages your app's DATE_FORMATS hash when parsing dates and times or specify your own format on a per-app, per-model, or per-attribute basis. Fails back to the default Ruby implementation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 1.6.0
>= 0
>= 0

Runtime

>= 3.0.0
 Project Readme

smart_time¶ ↑

The smart_time gem allows your date/time ActiveRecord attributes to be parsed using the formats already defined by you or Rails in Time::DATE_FORMATS and Date::DATE_FORMATS. This allows you to capture date/time from text input fields using format strings that are already used by Rails to convert Dates and Times to Strings. If a :format option is passed smart_time will force the use of the supplied format, otherwise it will attempt to parse using the formats defined in Time::DATE_FORMATS (for Times) and Date::DATE_FORMATS (for Dates). If none of the formats match it will fail back to using the default Rails/Ruby parsing technique. Requires Rails 3.

Getting Started¶ ↑

  1. Add smart_time to your Gemfile:

    gem 'smart_time'
    
  2. Install:

    bundle install
    
  3. Use the smart_time macro in your models

    class Event < ActiveRecord::Base
      # Calling smart_time with no parameters activates smart_time for all columns that have a
      # klass of Date or Time (aka db types :date, :time, :datetime, and :timestamp).
      smart_time
    
      # Or you can name just the attributes you want to activate
      # smart_time :start_at, :end_at
    
      # You can also explicitly pass a format string
      # smart_time :start_at, :format => "%m/%d/%Y"
    
    end
    
  4. Enjoy! If something breaks, complain to the author or (preferably) fork it, fix it, make sure all tests still pass and create a pull request.

Roadmap¶ ↑

  • Implement validation so that format errors can be properly displayed back to the view

Contributing to smart_time¶ ↑

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2011 Matthew Daubert. See LICENSE.txt for further details.