From 71d9536bc462bdae7b31bad0216baf4547fac0c2 Mon Sep 17 00:00:00 2001 From: vdumas Date: Wed, 21 Feb 2024 08:46:25 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B07268=20Method=20SetComputedDate=20fails?= =?UTF-8?q?=20on=20Date=20only=20attribute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit b6caa515522703dea91a058e01f18be13edd8340) (cherry picked from commit c8810708efd35f0b331f446f6212cf166ed8322c) --- core/dbobject.class.php | 2 +- .../unitary-tests/core/DBObjectTest.php | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 19a64c5ba..ea70321cf 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -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()); } /** diff --git a/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php b/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php index 6cf5b2604..5f1fe127e 100644 --- a/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php +++ b/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php @@ -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'); + + } }