Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-2286

Add MongoDB\BSON\UTCDateTime::toDateTimeImmutable

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 1.20.0
    • Affects Version/s: None
    • Component/s: None
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      The method MongoDB\BSON\UTCDateTime::toDateTime() returns a mutable DateTime instance. The community pushes for using ImmutableDateTime as much as possible.

       

      Currently, to get a DateTimeImmutable object from an UTCDateTime, developers have to do that:

      $date = new UTCDateTime();
      $dateTime = ImmutableDateTime::fromMutable($date->toDateTime());

      Proposed implementations:

      Add a method:

      $dateTime = $date->toDateTimeImmutable();

      Add a argument:

      $dateTime = $date->toDateTime(mutable: false);

      We can change the default value of mutable in 2.0 to return an immutable object by default. This change can be announced by deprecating not-passing an argument to the method.

            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:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: