Uploaded image for project: 'PHP ORMs'
  1. PHP ORMs
  2. PHPORM-230

Convert DateTimeInterface into UTCDateTime

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • laravel-5.0.0
    • Affects Version/s: None
    • Component/s: Laravel
    • None
    • PHP Drivers
    • Needed
    • Hide

      Document that using a DateTime object in a query or in input document, i is converted to UTCDateTime to be stored as a date in MongoDB.

      Show
      Document that using a DateTime object in a query or in input document, i is converted to UTCDateTime to be stored as a date in MongoDB.

      Laravel Database Connection automatically converts instances of DateTimeInterface into a string representing the date (source). This is done for every queries (where clauses, inserted data, updated data). DateTimeInterface instances are stored by MongoDB as empty objects: this is a frustrating user experience.
      To match Laravel’s behavior and improve developer experience, DateTimeInterface will be automatically converted to UTCDateTime in every command.

      This does not affect existing applications that already make this conversion before sending the command.

      Laravel doesn’t convert the result back to a Carbon instance. There are many opinionated choices that would have to be made: class, immutability, timezone. So it’s better if we keep returning the UTCDateTime. For models, the conversion is done by the cast.

            Assignee:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Reporter:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: