Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-179

Time part of Date fields is initialized with current time instead of 00:00:00

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA4
    • Fix Version/s: 2.0-ALPHA4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      This will be very easy for your to fix and it will help me a lot.

      AbstractPlatform:1510

      Change:

      public function getDateFormatString()
          {
              return 'Y-m-d';
          }
      

      By :

      public function getDateFormatString()
          {
              return '!Y-m-d';
          }
      

      Here is the extract from php documentation

          Format accepted by date().
      
          If format does not contain the character ! then portions of the date/time value specified in format but not specified in time will be set to the current system time.
      
          If format contains the character !, then portions of the generated time specified to the left-hand side of the ! in format will be set to corresponding values from the Unix epoch.
      
          If the first character of format is !, then all portions of the date/time value generated which are not specified in time will be initialized to corresponding values from the Unix epoch.
      
          The Unix epoch is 1970-01-01 00:00:00 UTC.
      
      

        Activity

        Hide
        Eric Durand-Tremblay added a comment -

        It look like it's more complicated.

        the ! break the date when it is used by convertToDatabaseValue

        So, it should only be used with convertToPHPValue

        Here is what it could look like in DateType.php:30

         public function convertToPHPValue($value, AbstractPlatform $platform)
            {
                return ($value !== null) 
                    ? \DateTime::createFromFormat('!' . $platform->getDateFormatString(), $value) : null;
            }
        
        Show
        Eric Durand-Tremblay added a comment - It look like it's more complicated. the ! break the date when it is used by convertToDatabaseValue So, it should only be used with convertToPHPValue Here is what it could look like in DateType.php:30 public function convertToPHPValue($value, AbstractPlatform $platform) { return ($value !== null ) ? \DateTime::createFromFormat('!' . $platform->getDateFormatString(), $value) : null ; }
        Hide
        Benjamin Eberlei added a comment -

        Looks like a no-brainer to me, however while thinking about it indenpendently of this issue we should probably add tests for summer-time annoyances that could occour.

        Show
        Benjamin Eberlei added a comment - Looks like a no-brainer to me, however while thinking about it indenpendently of this issue we should probably add tests for summer-time annoyances that could occour.
        Hide
        Benjamin Eberlei added a comment -

        Implemented

        Show
        Benjamin Eberlei added a comment - Implemented
        Hide
        Eric Durand-Tremblay added a comment -

        Look like you did not take into account my second comment.

        The insert/update of date value is now broken

        UPDATE client SET modified_at = ?, birthdate = ? WHERE id = ?                                          
        Array                                                                                                                  
        (                                                                                                                      
            [0] => 2010-01-14 15:14:20                                                                                         
            [1] => !2010-01-15                                                                                                                                                                                                
            [2] => 1                                                                                                           
        )     
        
        Show
        Eric Durand-Tremblay added a comment - Look like you did not take into account my second comment. The insert/update of date value is now broken UPDATE client SET modified_at = ?, birthdate = ? WHERE id = ? Array ( [0] => 2010-01-14 15:14:20 [1] => !2010-01-15 [2] => 1 )
        Hide
        Benjamin Eberlei added a comment -

        woah there is no test for this, bad

        Show
        Benjamin Eberlei added a comment - woah there is no test for this, bad
        Hide
        Roman S. Borschel added a comment -

        So can this be closed now?

        Show
        Roman S. Borschel added a comment - So can this be closed now?
        Hide
        Benjamin Eberlei added a comment -

        Yes, resolved!

        Show
        Benjamin Eberlei added a comment - Yes, resolved!

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Eric Durand-Tremblay
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: