Skip to content

Commit aa9c9d6

Browse files
johnnyshieldsjamis
andauthored
MONGOID-5676 [Monkey Patch Removal] Remove Time#configured (#5716)
* Removes Time#configured monkey patch. * Set UTC timezone by default * More spec cleanup * Re-add error check * add release notes for removal of `Time.configured` --------- Co-authored-by: Jamis Buck <[email protected]>
1 parent 389fd79 commit aa9c9d6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

source/release-notes/mongoid-9.0.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,46 @@ There are also rake tasks available, for convenience:
403403
$ rake mongoid:db:remove_search_indexes
404404

405405

406+
``Time.configured`` has been removed
407+
------------------------------------
408+
409+
``Time.configured`` returned either the time object wrapping the configured
410+
time zone, or the standard Ruby ``Time`` class. This allowed you to query
411+
a time value even if no time zone had been configured.
412+
413+
Mongoid now requires that you set a time zone if you intend to do
414+
anything with time values (including using timestamps in your documents).
415+
Any uses of ``Time.configured`` must be replaced with ``Time.zone``.
416+
417+
... code-block:: ruby
418+
419+
# before:
420+
puts Time.configured.now
421+
422+
# after:
423+
puts Time.zone.now
424+
425+
# or, better for finding the current Time specifically:
426+
puts Time.current
427+
428+
If you do not set a time zone, you will see errors in your code related
429+
to ``nil`` values. If you are using Rails, the default time zone is already
430+
set to UTC. If you are not using Rails, you may set a time zone at the start
431+
of your program like this:
432+
433+
... code-block:: ruby
434+
435+
Time.zone = 'UTC'
436+
437+
This will set the time zone to UTC. You can see all available time zone names
438+
by running the following command:
439+
440+
... code-block:: bash
441+
442+
$ ruby -ractive_support/values/time_zone \
443+
-e 'puts ActiveSupport::TimeZone::MAPPING.keys'
444+
445+
406446
Bug Fixes and Improvements
407447
--------------------------
408448

0 commit comments

Comments
 (0)