Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCSP-42957: DateTimeInterface in queries #3140

Merged
merged 10 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/includes/query-builder/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ public function testWhereIn(): void

public function testWhereDate(): void
{
// begin query whereDate
// begin query where date
$result = DB::connection('mongodb')
->table('movies')
->whereDate('released', '2010-1-15')
->where('released', Carbon::create(2010, 1, 15, 0, 0, 0, 'UTC'))
->get();
// end query whereDate
// end query where date

$this->assertInstanceOf(\Illuminate\Support\Collection::class, $result);
}
Expand Down
23 changes: 13 additions & 10 deletions docs/query-builder.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,23 +348,26 @@ query builder method to retrieve documents from the
Match Dates Example
^^^^^^^^^^^^^^^^^^^

The following example shows how to use the ``whereDate()``
The following example shows how to use the ``where()``
query builder method to retrieve documents from the
``movies`` collection that match the specified date of
``2010-1-15`` in the ``released`` field:
``movies`` collection in which the ``released`` value
is ``2010, 1, 15, 0, 0, 0``, specified in a ``Carbon`` object:
GromNaN marked this conversation as resolved.
Show resolved Hide resolved
GromNaN marked this conversation as resolved.
Show resolved Hide resolved

.. literalinclude:: /includes/query-builder/QueryBuilderTest.php
:language: php
:dedent:
:start-after: begin query whereDate
:end-before: end query whereDate
:start-after: begin query where date
:end-before: end query where date

.. note:: Date Query Result Type
.. note:: Date Query Filter and Result Type

Starting in {+odm-long+} v5.0, ``UTCDateTime`` BSON values in MongoDB
are returned as `Carbon <https://carbon.nesbot.com/docs/>`__ date
classes in query results. The {+odm-short+} applies the default
timezone when performing this conversion.
Starting in {+odm-long+} v5.0, `Carbon <https://carbon.nesbot.com/docs/>`__
objects passed as query filters, as shown in the preceding code, are
converted to ``UTCDateTime`` BSON values.

In query results, ``UTCDateTime`` BSON values in MongoDB are returned as ``Carbon``
objects. The {+odm-short+} applies the default timezone when performing
this conversion.

.. _laravel-query-builder-pattern:

Expand Down
10 changes: 10 additions & 0 deletions docs/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ This library version introduces the following breaking changes:
use the default ``Illuminate\Queue\Failed\DatabaseFailedJobProvider``
class and specify a connection to MongoDB.

- When using a ``DateTimeInterface`` object, including ``Carbon``, in a query,
the library converts the ``DateTimeInterface`` to a ``MongoDB\BSON\UTCDateTime``
object. This conversion applies to ``DateTimeInterface`` objects passed as query
filters to the ``where()`` method or as data passed to the ``insert()`` and
``update()`` methods.

For an example that passes a ``Carbon`` object to the
``DB::where()`` method, see the :ref:`laravel-query-builder-wheredate`
section of the Query Builder guide.
GromNaN marked this conversation as resolved.
Show resolved Hide resolved

- In query results, the library converts BSON ``UTCDateTime`` objects to ``Carbon``
date classes, applying the default timezone.

Expand Down
Loading