Development

#9471 (sfDoctrineRecord->getDateTimeObject returns current time)

You must first sign up to be able to contribute.

Ticket #9471 (new defect)

Opened 2 years ago

sfDoctrineRecord->getDateTimeObject returns current time

Reported by: katlim.ruiz Assigned to: fabien
Priority: major Milestone:
Component: model Version: 1.4.8
Keywords: sfDoctrineRecord DateTime Cc:
Qualification: Unreviewed

Description

When the underlying field has a null value and we call the method getDateTimeObject to obtain the DateTime? object, we get a new DateTime? object with the current time.

And this is because the constructor of the DateTime? automatically assigns the current date if a null parameter is passed on.

To me the solution should be: if the underlying field has a null value and the getDateTimeObject is called, the return value should also be a null value.

Before:

public function getDateTimeObject($dateFieldName) {

$type = $this->getTable()->getTypeOf($dateFieldName);

if ($type == 'date' $type == 'timestamp' $type == 'datetime') {

return new DateTime?($this->get($dateFieldName));

}

After

public function getDateTimeObject($dateFieldName) {

$type = $this->getTable()->getTypeOf($dateFieldName);

if ($type == 'date' $type == 'timestamp' $type == 'datetime') {

$d = $this->get($dateFieldName); return isset(d) ? new DateTime?(d) : null;

}