Rectangle 27 0

It looks like you need to specify the field type of your date attribute. I would use a Time field if you want mongoid to handle the zones properly.

class Lineup
  include Mongoid::Document
  field :date, type: Time

You will also probably want to set the following in config/mongoid.yml

defaults: &defaults
  use_utc: false
  use_activesupport_time_zone: true

This sounds counterintuitive, but this is the current way to make mongoid use UTC as the default timezone.

Finally, have a look at the mongoid-metastamp gem. It will give you much better support for querying across multiple timezones, while still seamlessly working like a native Time field.

This works with DateTime too in the current versions of Mongoid (I'm on 2.4.7). See

mongodb - How to save a timezone correctly with Ruby and MongoId? - St...

ruby mongodb time timezone mongoid
Rectangle 27 0

def self.activate_due
  events_due = Event.where(
     :eventStart.to_utc.lte =>(,
     :eventStart.to_utc.gte => (1.minute.ago.to_utc))
  events_due.each do |e|

Plesse note that this will work with UTC times, so if you have an event in UTC - 7 timezone don't think it will get activated now if the server timezone is UTC + 2

That helped. Thanks The main problem was in the switching, which happened once after the model was initiated and the timestamp already set.

timezone - Rails - How to save datetimes correctly in MongoID and trig...

ruby-on-rails timezone mongoid whenever