-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DateRange object implemented, exceptions refactored, tests update
- Loading branch information
Showing
14 changed files
with
300 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Utility\Object; | ||
|
||
/** | ||
* Class DateRange | ||
* | ||
* @category Object | ||
* @package Utility\Object | ||
* @author Alexandr Ivanov <misantron@gmail.com> | ||
* @license MIT https://github.com/misantron/php-utils/blob/master/LICENSE | ||
* @link https://github.com/misantron/php-utils/blob/master/src/UTime.php | ||
*/ | ||
class DateRange implements DateRangeInterface | ||
{ | ||
/** @var \DateTime */ | ||
private $rangeBegin; | ||
/** @var \DateTime */ | ||
private $rangeEnd; | ||
|
||
/** | ||
* @param mixed $dateBegin | ||
* @param mixed $dateEnd | ||
*/ | ||
function __construct($dateBegin, $dateEnd) | ||
{ | ||
if (is_int($dateBegin)) { | ||
$this->rangeBegin = (new \DateTime())->setTimestamp($dateBegin); | ||
} elseif (is_string($dateBegin)) { | ||
$this->rangeBegin = new \DateTime($dateBegin); | ||
} elseif ($dateBegin instanceof \DateTime) { | ||
$this->rangeBegin = $dateBegin; | ||
} else { | ||
throw new \InvalidArgumentException('$dateBegin argument format is invalid.'); | ||
} | ||
|
||
if (is_int($dateEnd)) { | ||
$this->rangeEnd = (new \DateTime())->setTimestamp($dateEnd); | ||
} elseif (is_string($dateEnd)) { | ||
$this->rangeEnd = new \DateTime($dateEnd); | ||
} elseif ($dateEnd instanceof \DateTime) { | ||
$this->rangeEnd = $dateEnd; | ||
} else { | ||
throw new \InvalidArgumentException('$dateEnd argument format is invalid.'); | ||
} | ||
} | ||
|
||
/** | ||
* @return \DateTime | ||
*/ | ||
public function getRangeBegin() | ||
{ | ||
return $this->rangeBegin; | ||
} | ||
|
||
/** | ||
* @return \DateTime | ||
*/ | ||
public function getRangeEnd() | ||
{ | ||
return $this->rangeEnd; | ||
} | ||
|
||
/** | ||
* @return \DateTime[] | ||
*/ | ||
public function toArray() | ||
{ | ||
return [$this->rangeBegin, $this->rangeEnd]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Utility\Object; | ||
|
||
/** | ||
* Interface DateRangeInterface | ||
* | ||
* @category Object | ||
* @package Utility\Object | ||
* @author Alexandr Ivanov <misantron@gmail.com> | ||
* @license MIT https://github.com/misantron/php-utils/blob/master/LICENSE | ||
* @link https://github.com/misantron/php-utils/blob/master/src/UTime.php | ||
*/ | ||
interface DateRangeInterface | ||
{ | ||
/** | ||
* @return \DateTime | ||
*/ | ||
public function getRangeBegin(); | ||
|
||
/** | ||
* @return \DateTime | ||
*/ | ||
public function getRangeEnd(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.