DDC-179: Time part of Date fields is initialized with current time instead of 00:00:00 #2440

Closed
doctrinebot opened this Issue Nov 26, 2009 · 9 comments

2 participants

@doctrinebot

Jira issue originally created by user rickdt:

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.

@doctrinebot

Comment created by rickdt:

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;
    }
@doctrinebot

Comment created by @beberlei:

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.

@doctrinebot

Comment created by @beberlei:

Implemented

@doctrinebot

Comment created by rickdt:

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                                                                                                           
)     
@doctrinebot

Comment created by @beberlei:

woah there is no test for this, bad :-)

@doctrinebot

Comment created by romanb:

So can this be closed now?

@doctrinebot

Comment created by @beberlei:

Yes, resolved!

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.0-ALPHA4 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment