Skip to content

DOCSP-43158: carbon date values db query results #3133

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

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions docs/eloquent-models/model-class.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ type, to the Laravel ``datetime`` type.
To learn more, see `Attribute Casting <https://laravel.com/docs/{+laravel-docs-version+}/eloquent-mutators#attribute-casting>`__
in the Laravel documentation.

This conversion lets you use the PHP `DateTime <https://www.php.net/manual/en/class.datetime.php>`__
or the `Carbon class <https://carbon.nesbot.com/docs/>`__ to work with dates
This conversion lets you use the PHP `DateTime
<https://www.php.net/manual/en/class.datetime.php>`__ class to work with dates
in this field. The following example shows a Laravel query that uses the
casting helper on the model to query for planets with a ``discovery_dt`` of
less than three years ago:
Expand All @@ -226,6 +226,13 @@ less than three years ago:

Planet::where( 'discovery_dt', '>', new DateTime('-3 years'))->get();

.. note:: Carbon Date Class

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.

To learn more about MongoDB's data types, see :manual:`BSON Types </reference/bson-types/>`
in the Server manual.

Expand Down
7 changes: 7 additions & 0 deletions docs/query-builder.txt
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ query builder method to retrieve documents from the
:start-after: begin query whereDate
:end-before: end query whereDate

.. note:: Date Query 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.

.. _laravel-query-builder-pattern:

Text Pattern Match Example
Expand Down
15 changes: 14 additions & 1 deletion docs/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Overview

On this page, you can learn how to upgrade {+odm-long+} to a new major version.
This page also includes the changes you must make to your application to upgrade
your object-document mapper (ODM) version without losing functionality, if applicable.
your version of the {+odm-short+} without losing functionality, if applicable.

How to Upgrade
--------------
Expand Down Expand Up @@ -61,6 +61,19 @@ version releases that introduced them. When upgrading library versions,
address all the breaking changes between your current version and the
planned upgrade version.

- :ref:`laravel-breaking-changes-v5.x`
- :ref:`laravel-breaking-changes-v4.x`

.. _laravel-breaking-changes-v5.x:

Version 5.x Breaking Changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This library version introduces the following breaking changes:

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

.. _laravel-breaking-changes-v4.x:

Version 4.x Breaking Changes
Expand Down
Loading