开发者

Store TimeZone with Mongoid

开发者 https://www.devze.com 2023-04-12 05:46 出处:网络
I have the following Mongoid model... class Eve开发者_运维百科nt include Mongoid::Document include Mongoid::Timestamps::Created

I have the following Mongoid model...

class Eve开发者_运维百科nt
  include Mongoid::Document
  include Mongoid::Timestamps::Created
  include Mongoid::Timestamps::Updated
  include Mongoid::MultiParameterAttributes

  key :name

  field :name
  field :begins_at, type: Time
  field :ends_at, type: Time

  belongs_to :city

  attr_accessor :time_zone
end

I'd like to be able to have a per-event TimeZone. Obviously due to the complications of time zones the best way to handle this is to store times in UTC when going to the DB and convert back to the event's time zone on the way out of the DB.

I know ActiveRecord has support for this and I was wondering if Mongoid has any kind of native support for this.


Store as: timestamp and when query Format to timezone

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号