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

UTCDateTime::toDateTime() does not properly set microseconds

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.1.8
    • Affects Version/s: 1.1.4
    • Component/s: None
    • None
    • Environment:
      PHP 5.6.14
      pecl-mongodb v1.1.4

      This issue manifests itself when attempting to round-trip the exported DateTime value through PHP serialization. Here, we would expect the microseconds to be "234000" instead of "234000000". Likewise, the "date" string should only be 26 characters long.

      $udt = new MongoDB\BSON\UTCDateTime((time() * 1000) + 1234); 
      $d = $udt->toDateTime(); 
      $s = serialize($d);
      
      print("$s\n");
      print_r(unserialize($s));
      

      Output:

      O:8:"DateTime":3:{s:4:"date";s:29:"2016-03-11 22:04:02.234000000";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}
      
      PHP Fatal error:  Invalid serialization data for DateTime object in Command line code on line 1
      
      Fatal error: Invalid serialization data for DateTime object in Command line code on line 1
      

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: