N°7268 Method SetComputedDate fails on Date only attribute

(cherry picked from commit b6caa51552)
(cherry picked from commit c8810708ef)
This commit is contained in:
vdumas
2024-02-21 08:46:25 +01:00
committed by Pierre Goiffon
parent 6377a738c5
commit 71d9536bc4
2 changed files with 28 additions and 1 deletions

View File

@@ -4229,7 +4229,7 @@ abstract class DBObject implements iDisplay
}
}
$oDate->modify($sModifier);
$this->Set($sAttCode, $oDate->format('Y-m-d H:i:s'));
$this->Set($sAttCode, $oDate->getTimestamp());
}
/**

View File

@@ -539,4 +539,31 @@ class DBObjectTest extends ItopDataTestCase
return $oUserWithAllowedOrgs;
}
/**
* @covers DBObject::SetComputedDate
* @return void
*/
public function testSetComputedDateOnAttributeDate()
{
$oObject = MetaModel::NewObject(\CustomerContract::class, ['name' => 'Test contract', 'org_id' => '3', 'provider_id' => '2']);
$oObject->Set('start_date', time());
$oObject->SetComputedDate('end_date', "+2 weeks", 'start_date');
$this->assertTrue(true, 'No fatal error on computing date');
}
/**
* @covers DBObject::SetComputedDate
* @return void
*/
public function testSetComputedDateOnAttributeDateTime()
{
$oObject = MetaModel::NewObject(\WorkOrder::class, ['name' => 'Test workorder', 'description' => 'Toto']);
$oObject->Set('start_date', '2024-01-01 09:45:00');
$oObject->SetComputedDate('end_date', "+2 weeks", 'start_date');
$this->assertTrue(true, 'No fatal error on computing date');
$this->assertEquals("2024-01-15 09:45:00", $oObject->Get('end_date'), 'SetComputedDate +2 weeks on a WorkOrder DateTimeAttribute');
}
}