lib/mongoid/extensions/date.rb in mongoid-8.1.7 vs lib/mongoid/extensions/date.rb in mongoid-9.0.0

- old
+ new

@@ -1,9 +1,12 @@ # frozen_string_literal: true +# rubocop:todo all module Mongoid module Extensions + + # Adds type-casting behavior to Date class. module Date # Convert the date into a time. # # @example Convert the date to a time. @@ -12,11 +15,11 @@ # # @return [ Time | ActiveSupport::TimeWithZone ] Local time in the # configured default time zone corresponding to local midnight of # this date. def __mongoize_time__ - ::Time.configured.local(year, month, day) + ::Time.zone.local(year, month, day) end # Turn the object from the ruby type we deal with to a Mongo friendly # type. # @@ -66,11 +69,13 @@ return if object.blank? begin if object.is_a?(String) # https://jira.mongodb.org/browse/MONGOID-4460 time = ::Time.parse(object) - else + elsif object.respond_to?(:__mongoize_time__) time = object.__mongoize_time__ + else + nil end rescue ArgumentError nil end if time.acts_like?(:time)