Files
pathfinder/app/Lib/DateRange.php
Mark Friedrich 647bd7db58 - BC Break: _PHP_ namespaces changed (PSR-4 standard). The _root_ namespace for all _PF_ related scripts is Exodus4D\Pathfinder
- BC Break: Project folder structure changed. Removed `app/main` dir.
- BC Break: Core _PHP_ framework + dependencies moved into `composer.json` and are no longer part of this repo
2019-12-15 22:27:17 +01:00

55 lines
1.1 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: Exodus 4D
* Date: 29.11.2018
* Time: 18:06
*/
namespace Exodus4D\Pathfinder\Lib;
use Exodus4D\Pathfinder\Exception\DateException;
class DateRange {
/**
* from range start
* @var \DateTime
*/
protected $from;
/**
* to range end
* @var \DateTime
*/
protected $to;
/**
* DateRange constructor.
* @param \DateTime $from
* @param \DateTime $to
* @throws DateException
*/
public function __construct(\DateTime $from, \DateTime $to){
if($from == $to){
throw new DateException('A period cannot be the same time', 3000);
}else{
if($from < $to){
$this->from = $from;
$this->to = $to;
} else {
$this->from = $to;
$this->to = $from;
}
}
}
/**
* check if DateTime $dateCheck is within this range
* @param \DateTime $dateCheck
* @return bool
*/
public function inRange(\DateTime $dateCheck) : bool {
return $dateCheck >= $this->from && $dateCheck <= $this->to;
}
}