mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-10 22:18:40 +00:00
the start and end of a day can be created
This commit is contained in:
parent
0f09da42e9
commit
adc31a21b2
|
|
@ -194,6 +194,30 @@ class SmartDateTime extends \DateTime
|
||||||
return \getdate(\mktime(0, 0, 0, (int) $this->format('m'), 1, (int) $this->format('Y')))['wday'];
|
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
|
* Is leap year in gregorian calendar
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,32 @@ class SmartDateTimeTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertEquals($expected->format('Y-m-d'), $obj->getStartOfWeek()->format('Y-m-d'));
|
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
|
* @testdox A date or year can be checked if it is a leap year
|
||||||
* @covers phpOMS\Stdlib\Base\SmartDateTime
|
* @covers phpOMS\Stdlib\Base\SmartDateTime
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user