Skip to content

Commit 9695803

Browse files
MONGOID-5488 - Bugfix: Date#__evolve_time__ should use the configured zone instead of Time.local (i.e. respecting Mongoid.use_activesupport_time_zone) (#5471)
* Date#__evolve_time__ should use the configured zone. Currently it uses "local" (not "UTC") which is not affected by Rails configuration. * Make consistent with Mongoize * Add changelog * Update docs/release-notes/mongoid-9.0.txt * Update docs/release-notes/mongoid-9.0.txt * Update mongoid-9.0.txt Co-authored-by: shields <shields@tablecheck.com> Co-authored-by: Oleg Pudeyev <39304720+p-mongo@users.noreply.github.com>
1 parent 56f329d commit 9695803

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

source/release-notes/mongoid-9.0.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,36 @@ any Mongoid-specific usages of this class, and change them to
4040
``Mongoid::Errors::AttributeNotLoaded``. Note additionally that
4141
``AttributeNotLoaded`` inherits from ``Mongoid::Errors::MongoidError``,
4242
while ``ActiveModel::MissingAttributeError`` does not.
43+
44+
45+
Use configured time zone to typecast Date to Time in queries
46+
-------------------------------------------------------------
47+
48+
When querying for a Time field using a Date value, Mongoid now correctly
49+
considers the ``Mongoid.use_activesupport_time_zone`` configuration option
50+
to perform type conversion.
51+
52+
.. code-block:: ruby
53+
54+
Mongoid.use_activesupport_time_zone = true
55+
56+
class Magazine
57+
include Mongoid::Document
58+
59+
field :published_at, type: Time
60+
end
61+
62+
Time.zone = 'Asia/Tokyo'
63+
64+
Magazine.gte(published_at: Date.parse('2022-09-26'))
65+
#=> will return all results on or after Sept 26th, 2022
66+
# at 0:00 in Asia/Tokyo time zone.
67+
68+
In prior Mongoid versions, the above code would ignore the
69+
``Mongoid.use_activesupport_time_zone`` setting and behave as if
70+
it were false, i.e. always using the system time zone to perform
71+
the type conversion.
72+
73+
Note that in prior Mongoid versions, typecasting Date to Time during
74+
persistence operations was already correctly using the
75+
``Mongoid.use_activesupport_time_zone`` setting.

0 commit comments

Comments
 (0)