DatePeriod - change namespace (Meritoo\Common\Utilities -> Meritoo\Common\Type) & extend BaseType

This commit is contained in:
Meritoo
2017-11-03 20:21:08 +01:00
parent 6d4e422165
commit edc51aeee1
4 changed files with 75 additions and 76 deletions

View File

@@ -6,9 +6,11 @@
* file that was distributed with this source code.
*/
namespace Meritoo\Common\Utilities;
namespace Meritoo\Common\Type;
use DateTime;
use Meritoo\Common\Type\Base\BaseType;
use Meritoo\Common\Utilities\Date;
/**
* A date's period.
@@ -17,7 +19,7 @@ use DateTime;
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl
*/
class DatePeriod
class DatePeriod extends BaseType
{
/**
* The period constant: last month
@@ -108,17 +110,6 @@ class DatePeriod
$this->endDate = $endDate;
}
/**
* Returns information if given period is correct
*
* @param int $period The period to verify
* @return bool
*/
public static function isCorrectPeriod($period)
{
return in_array($period, Reflection::getConstants(__CLASS__));
}
/**
* Returns formatted one of the period's date: start date or end date
*

View File

@@ -12,6 +12,7 @@ use DateInterval;
use DateTime;
use Meritoo\Common\Exception\Date\UnknownDatePartTypeException;
use Meritoo\Common\Type\DatePartType;
use Meritoo\Common\Type\DatePeriod;
/**
* Useful date methods
@@ -72,7 +73,7 @@ class Date
{
$datePeriod = null;
if (DatePeriod::isCorrectPeriod($period)) {
if ((new DatePeriod())->isCorrectType($period)) {
$dateStart = null;
$dateEnd = null;