Module: Mongoid::Extensions::Date

Defined in:
build/mongoid-7.3/lib/mongoid/extensions/date.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

EPOCH =
Deprecated.

No longer used as a return value from #mongoize passed an invalid date string.

Constant for epoch - used when passing invalid times.

::Date.new(1970, 1, 1)

Instance Method Summary collapse

Instance Method Details

#__mongoize_time__Time | ActiveSupport::TimeWithZone

Convert the date into a time.

Examples:

Convert the date to a time.

Date.new(2018, 11, 1).__mongoize_time__
# => Thu, 01 Nov 2018 00:00:00 EDT -04:00

Returns:

  • (Time | ActiveSupport::TimeWithZone)

    Local time in the configured default time zone corresponding to local midnight of this date.

Since:

  • 3.0.0



25
26
27
# File 'build/mongoid-7.3/lib/mongoid/extensions/date.rb', line 25

def __mongoize_time__
  ::Time.configured.local(year, month, day)
end

#mongoizeTime

Turn the object from the ruby type we deal with to a Mongo friendly type.

Examples:

Mongoize the object.

date.mongoize

Returns:

  • (Time)

    The object mongoized.

Since:

  • 3.0.0



38
39
40
# File 'build/mongoid-7.3/lib/mongoid/extensions/date.rb', line 38

def mongoize
  ::Date.mongoize(self)
end