Skip to content

EspoCRM – Open Source CRM Application

addSeconds function

Yuri Kuznetsov15691fc8b0fe
diff --git a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddDaysType.php b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddDaysType.php
index 304062aa96..2ad372d063 100644
--- a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddDaysType.php
+++ b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddDaysType.php
@@ -31,5 +31,5 @@ namespace Espo\Core\Formula\Functions\DatetimeGroup;
class AddDaysType extends AddIntervalType
{
- protected $intervalTypeString = 'days';
+ protected string $intervalTypeString = 'days';
}
diff --git a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddHoursType.php b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddHoursType.php
index 5b38eb32f6..c68ed39061 100644
--- a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddHoursType.php
+++ b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddHoursType.php
@@ -31,7 +31,6 @@ namespace Espo\Core\Formula\Functions\DatetimeGroup;
class AddHoursType extends AddIntervalType
{
- protected $intervalTypeString = 'hours';
-
- protected $timeOnly = true;
+ protected string $intervalTypeString = 'hours';
+ protected bool $timeOnly = true;
}
diff --git a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddIntervalType.php b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddIntervalType.php
index b9e1e2b04a..2342cde627 100644
--- a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddIntervalType.php
+++ b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddIntervalType.php
@@ -42,15 +42,8 @@ abstract class AddIntervalType extends BaseFunction implements Di\DateTimeAware
{
use Di\DateTimeSetter;
- /**
- * @var bool
- */
- protected $timeOnly = false;
-
- /**
- * @var string
- */
- protected $intervalTypeString;
+ protected bool $timeOnly = false;
+ protected string $intervalTypeString;
public function process(ArgumentList $args)
{
diff --git a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddMinutesType.php b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddMinutesType.php
index 1b3419135f..5d06aafe3b 100644
--- a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddMinutesType.php
+++ b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddMinutesType.php
@@ -31,13 +31,7 @@ namespace Espo\Core\Formula\Functions\DatetimeGroup;
class AddMinutesType extends AddIntervalType
{
- /**
- * @var string
- */
- protected $intervalTypeString = 'minutes';
- /**
- * @var bool
- */
- protected $timeOnly = true;
+ protected string $intervalTypeString = 'minutes';
+ protected bool $timeOnly = true;
}
diff --git a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddMonthsType.php b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddMonthsType.php
index 44ae7f68ff..192ec55eec 100644
--- a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddMonthsType.php
+++ b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddMonthsType.php
@@ -31,8 +31,5 @@ namespace Espo\Core\Formula\Functions\DatetimeGroup;
class AddMonthsType extends AddIntervalType
{
- /**
- * @var string
- */
- protected $intervalTypeString = 'months';
+ protected string $intervalTypeString = 'months';
}
diff --git a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddSecondsType.php b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddSecondsType.php
new file mode 100644
index 0000000000..85ba87b0bd
--- /dev/null
+++ b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddSecondsType.php
@@ -0,0 +1,36 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2025 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
+ * Website: https://www.espocrm.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU Affero General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
+ ************************************************************************/
+
+namespace Espo\Core\Formula\Functions\DatetimeGroup;
+
+class AddSecondsType extends AddIntervalType
+{
+ protected string $intervalTypeString = 'seconds';
+ protected bool $timeOnly = true;
+}
diff --git a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddWeeksType.php b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddWeeksType.php
index 1e1c3d0752..3f4d940155 100644
--- a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddWeeksType.php
+++ b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddWeeksType.php
@@ -31,8 +31,5 @@ namespace Espo\Core\Formula\Functions\DatetimeGroup;
class AddWeeksType extends AddIntervalType
{
- /**
- * @var string
- */
- protected $intervalTypeString = 'weeks';
+ protected string $intervalTypeString = 'weeks';
}
diff --git a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddYearsType.php b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddYearsType.php
index 25ad5f76bb..b75a599c72 100644
--- a/application/Espo/Core/Formula/Functions/DatetimeGroup/AddYearsType.php
+++ b/application/Espo/Core/Formula/Functions/DatetimeGroup/AddYearsType.php
@@ -31,8 +31,5 @@ namespace Espo\Core\Formula\Functions\DatetimeGroup;
class AddYearsType extends AddIntervalType
{
- /**
- * @var string
- */
- protected $intervalTypeString = 'years';
+ protected string $intervalTypeString = 'years';
}
diff --git a/tests/unit/Espo/Core/Formula/FormulaTest.php b/tests/unit/Espo/Core/Formula/FormulaTest.php
index fcb17ad1a9..8410a7c86c 100644
--- a/tests/unit/Espo/Core/Formula/FormulaTest.php
+++ b/tests/unit/Espo/Core/Formula/FormulaTest.php
@@ -2236,6 +2236,24 @@ class FormulaTest extends TestCase
'));
$actual = $this->createProcessor()->process($item);
$this->assertEquals('2017-01-01 19:30:00', $actual);
+
+ $item = new Argument(self::stringToNode('
+ {
+ "type": "datetime\\\\addSeconds",
+ "value": [
+ {
+ "type": "value",
+ "value": "2025-01-01 20:00:00"
+ },
+ {
+ "type": "value",
+ "value": -30
+ }
+ ]
+ }
+ '));
+ $actual = $this->createProcessor()->process($item);
+ $this->assertEquals('2025-01-01 19:59:30', $actual);
}
function testDatetimeClosestTime()