From 0dd34df7d7f4bb4f8ebdc287d71febeaa86062e3 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 29 Feb 2024 10:10:33 +0200 Subject: [PATCH] isWorkingDay fix --- .../Tools/WorkingTime/CalendarUtility.php | 2 +- .../Espo/Tools/WorkingTime/UtilityTest.php | 58 +++++++++++++++++++ .../Tools/WorkingTime/CalendarUtilityTest.php | 2 +- 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 tests/integration/Espo/Tools/WorkingTime/UtilityTest.php diff --git a/application/Espo/Tools/WorkingTime/CalendarUtility.php b/application/Espo/Tools/WorkingTime/CalendarUtility.php index 2a89b243d8..8f4de51219 100644 --- a/application/Espo/Tools/WorkingTime/CalendarUtility.php +++ b/application/Espo/Tools/WorkingTime/CalendarUtility.php @@ -53,7 +53,7 @@ class CalendarUtility ->withTimezone($this->calendar->getTimezone()) ->withTime(0, 0, 0); - return $this->extractor->extractAllDay($this->calendar, $point, $point->modify('+1 day')) !== []; + return $this->extractor->extractAllDay($this->calendar, $point, $point->modify('+0 seconds')) !== []; } public function hasWorkingTime(DateTime $from, DateTime $to): bool diff --git a/tests/integration/Espo/Tools/WorkingTime/UtilityTest.php b/tests/integration/Espo/Tools/WorkingTime/UtilityTest.php new file mode 100644 index 0000000000..6db91737f9 --- /dev/null +++ b/tests/integration/Espo/Tools/WorkingTime/UtilityTest.php @@ -0,0 +1,58 @@ +. + * + * 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 tests\integration\Espo\Tools\WorkingTime; + +use Espo\Core\Field\DateTime; +use Espo\Entities\WorkingTimeCalendar; +use Espo\Tools\WorkingTime\CalendarUtilityFactory; +use tests\integration\Core\BaseTestCase; + +class UtilityTest extends BaseTestCase +{ + public function testUtility(): void + { + $em = $this->getEntityManager(); + + $calendar = $em->createEntity(WorkingTimeCalendar::ENTITY_TYPE); + + $user = $this->createUser('test'); + $user->set('workingTimeCalendarId', $calendar->getId()); + $em->saveEntity($user); + + $utility = $this->getInjectableFactory() + ->create(CalendarUtilityFactory::class) + ->createForUser($user); + + $this->assertTrue($utility->isWorkingDay(DateTime::fromString('2024-02-23 00:00'))); + $this->assertFalse($utility->isWorkingDay(DateTime::fromString('2024-02-24 00:00'))); + $this->assertFalse($utility->isWorkingDay(DateTime::fromString('2024-02-25 00:00'))); + $this->assertTrue($utility->isWorkingDay(DateTime::fromString('2024-02-26 00:00'))); + } +} diff --git a/tests/unit/Espo/Tools/WorkingTime/CalendarUtilityTest.php b/tests/unit/Espo/Tools/WorkingTime/CalendarUtilityTest.php index 222a066c74..f4769b003a 100644 --- a/tests/unit/Espo/Tools/WorkingTime/CalendarUtilityTest.php +++ b/tests/unit/Espo/Tools/WorkingTime/CalendarUtilityTest.php @@ -52,7 +52,7 @@ class CalendarUtilityTest extends \PHPUnit\Framework\TestCase $time = DateTime::fromString('2023-01-01 01:01:01'); $from = DateTime::fromString('2023-01-01 00:00:00'); - $to = DateTime::fromString('2023-01-02 00:00:00'); + $to = DateTime::fromString('2023-01-01 00:00:00'); $this->extractor ->expects($this->any())