No commit activity in last 3 years
No release in over 3 years
A Mongoid wrapper for Time objects that retains the timezone name
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0
~> 3.1.0

Runtime

 Project Readme

Mongoid Time With Named Zone

Timezones can be a developer's worst nightmare and introduce subtle bugs.

This gem provides a Mongoid wrapper for Time objects that includes and retains the timezone name as a string.

Reading from the database will use the ActiveSupport::TimeWithZone's monkey patched #in_time_zone (monkey patched by Mongoid) to convert the time to being a TimeWithZone.

This gem does not apply any monkey patches.

This is necessary because MongoDB can save ISO8601 formatted date strings by using a wrapping type ISODate(), but these don't include the strings representing the name of the timezone. This gem stores timezone string in the database.

Usage

with Bundler, add this gem to your Gemfile:

gem 'mongoid-time_with_named_zone'

requiring manually:

require 'mongoid/time_with_named_zone'

Define your Mongoid models with field types of Mongoid::TimeWithNamedZone:

e.g.:

class BlogPost

  field :published_at, type: Mongoid::TimeWithNamedZone
  field :body,         type: String

end

and assign attributes to Time instances:

post = BlogPost.new
post.published_at = Time.now.in_time_zone('Pacific/Auckland')

Testing

Run rake spec

Contributing changes

Once you've made your great commits:

  1. Fork time-with-zone
  2. Create a topic branch - git checkout -b my_branch
  3. Push to your branch - git push origin my_branch
  4. Open a Pull Request to discuss your changes

That's it!

License

See LICENSE