diff --git a/Stdlib/Base/SmartDateTime.php b/Stdlib/Base/SmartDateTime.php index 37b1bc4a8..5eb025e54 100644 --- a/Stdlib/Base/SmartDateTime.php +++ b/Stdlib/Base/SmartDateTime.php @@ -194,6 +194,30 @@ class SmartDateTime extends \DateTime return \getdate(\mktime(0, 0, 0, (int) $this->format('m'), 1, (int) $this->format('Y')))['wday']; } + /** + * Get the end of the day + * + * @return SmartDateTime + * + * @since 1.0.0 + */ + public function getEndOfDay() : self + { + return new self(\date('Y-m-d', $this->getTimestamp()) . ' 23:59:59'); + } + + /** + * Get the start of the day + * + * @return SmartDateTime + * + * @since 1.0.0 + */ + public function getStartOfDay() : self + { + return new self(\date('Y-m-d', $this->getTimestamp()) . ' 00:00:00'); + } + /** * Is leap year in gregorian calendar * diff --git a/tests/Stdlib/Base/SmartDateTimeTest.php b/tests/Stdlib/Base/SmartDateTimeTest.php index 2e8e5d6f6..3104006c4 100644 --- a/tests/Stdlib/Base/SmartDateTimeTest.php +++ b/tests/Stdlib/Base/SmartDateTimeTest.php @@ -154,6 +154,32 @@ class SmartDateTimeTest extends \PHPUnit\Framework\TestCase self::assertEquals($expected->format('Y-m-d'), $obj->getStartOfWeek()->format('Y-m-d')); } + /** + * @testdox A smart datetime can be returned of the end of the day + * @covers phpOMS\Stdlib\Base\SmartDateTime + * @group framework + */ + public function testEndOfDay() : void + { + $expected = new \DateTime('2019-11-17'); + $obj = new SmartDateTime('2019-11-21'); + + self::assertEquals($expected->format('Y-m-d') . '23:59:59', $obj->getEndOfDay()->format('Y-m-d H:i:s')); + } + + /** + * @testdox A smart datetime can be returned of the start of the day + * @covers phpOMS\Stdlib\Base\SmartDateTime + * @group framework + */ + public function testStartOfDay() : void + { + $expected = new \DateTime('2019-11-17'); + $obj = new SmartDateTime('2019-11-21'); + + self::assertEquals($expected->format('Y-m-d') . '00:00:00', $obj->getStartOfDay()->format('Y-m-d H:i:s')); + } + /** * @testdox A date or year can be checked if it is a leap year * @covers phpOMS\Stdlib\Base\SmartDateTime