Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoid-time_with_named_zone

Package Overview
Dependencies
Maintainers
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoid-time_with_named_zone

  • 0.2.2
  • Rubygems
  • Socket score

Version published
Maintainers
3
Created
Source

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

FAQs

Package last updated on 07 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc