diff --git a/application/Espo/Core/Formula/Functions/DatetimeGroup/DayOfWeekType.php b/application/Espo/Core/Formula/Functions/DatetimeGroup/DayOfWeekType.php index 7676de85b1..55191f5355 100644 --- a/application/Espo/Core/Formula/Functions/DatetimeGroup/DayOfWeekType.php +++ b/application/Espo/Core/Formula/Functions/DatetimeGroup/DayOfWeekType.php @@ -54,18 +54,15 @@ class DayOfWeekType extends \Espo\Core\Formula\Functions\Base $value = $this->evaluate($item->value[0]); - if (empty($value)) return 0; + if (empty($value)) return -1; if (strlen($value) > 11) { - $resultString = $this->getInjection('dateTime')->convertSystemDateTime($value, null, 'D'); + $resultString = $this->getInjection('dateTime')->convertSystemDateTime($value, null, 'e'); } else { - $resultString = $this->getInjection('dateTime')->convertSystemDate($value, 'D'); + $resultString = $this->getInjection('dateTime')->convertSystemDate($value, 'e'); } - $result = intval($resultString) + 1; - if ($result == 8) { - $result = 1; - } + $result = intval($resultString); return $result; } diff --git a/tests/unit/Espo/Core/Formula/FormulaTest.php b/tests/unit/Espo/Core/Formula/FormulaTest.php index eafe279c3c..82640671a9 100644 --- a/tests/unit/Espo/Core/Formula/FormulaTest.php +++ b/tests/unit/Espo/Core/Formula/FormulaTest.php @@ -1352,7 +1352,7 @@ class FormulaTest extends \PHPUnit_Framework_TestCase } '); $actual = $this->formula->process($item); - $this->assertEquals(6, $actual); + $this->assertEquals(5, $actual); $item = json_decode(' { @@ -1366,7 +1366,35 @@ class FormulaTest extends \PHPUnit_Framework_TestCase } '); $actual = $this->formula->process($item); - $this->assertEquals(1, $actual); + $this->assertEquals(0, $actual); + + $item = json_decode(' + { + "type": "datetime\\\\dayOfWeek", + "value": [ + { + "type": "value", + "value": "" + } + ] + } + '); + $actual = $this->formula->process($item); + $this->assertEquals(-1, $actual); + + $item = json_decode(' + { + "type": "datetime\\\\dayOfWeek", + "value": [ + { + "type": "value", + "value": "2017-05-12" + } + ] + } + '); + $actual = $this->formula->process($item); + $this->assertEquals(5, $actual); } function testDatetimeDiff()