the start and end of a day can be created

This commit is contained in:
Dennis Eichhorn 2019-12-21 12:25:33 +01:00
parent 0f09da42e9
commit adc31a21b2
2 changed files with 50 additions and 0 deletions

View File

@ -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
*

View File

@ -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