mongoid_time_field¶ ↑
Simple gem to store minutes+seconds or hours+minutes in one integer field in mongoid (as you would do in mysql with time field)
<img src=“https://travis-ci.org/glebtv/mongoid_time_field.svg?branch=master” alt=“Build Status” />
Installation¶ ↑
Include the gem in your Gemfile
gem 'mongoid_time_field'
Usage¶ ↑
class DummyTime include Mongoid::Document field :worktime, type: TimeField.new(format: 'HH:MM') field :time_of_day, type: TimeField.new(format: 'HH:MM:SS') field :duration, type: TimeField.new(format: 'mm:SS') end
Format tokens:¶ ↑
SS - Seconds (always two digits) MM - Minutes, zero-padded mm - minutes, no padding HH - hours, zero-padded to two hh - hours, no padding hh? - hours, displays hours only if they are present (non-zero) Default format is 'hh?:mm:SS'.
Leftmost value in format is of arbitrary length (i.e. format ‘HH:MM’ is not limited to 24 hours, ‘mm:SS’ is not limited to 60 minutes and should not overflow)
All time values are converted and stored in mongodb as seconds (integer field).
changes since v.0.1.0¶ ↑
Default format for deprecated time_field syntax is ‘mm:SS’ for compatibility (If you stored HH:MM with 0.1.0 it should still just keep working with ‘mm:SS’ format, with seconds stored in DB, but if you change to new syntax and use ‘HH:MM’ format, you need to multiply all stored values by 60)
Contributing to mongoid_time_field¶ ↑
-
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¶ ↑
Copyright © 2012-2013 glebtv. See LICENSE.txt for further details.