<?php
/*
* Limb PHP Framework
*
* @link http://limb-project.com
* @copyright Copyright © 2004-2009 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/datetime/src/lmbDateTime.class.php');
lmb_require('limb/core/src/exception/lmbException.class.php');
/**
* class lmbDateTimePeriod.
*
* @package datetime
* @version $Id: lmbDateTimePeriod.class.php 6243 2007-08-29 11:53:10Z pachanga $
*/
class lmbDateTimePeriod
{
protected $start;
protected $end;
function __construct($start, $end)
{
$this->start = (is_object($start)) ? $start : new lmbDateTime($start);
$this->end = (is_object($end)) ? $end : new lmbDateTime($end);
if($this->end->isBefore($this->start))
throw new lmbException('Wrong period interval', array('start' => $this->start->toString(),
'end' => $this->end->toString()));
}
function toString()
{
return $this->start->toString() . ' - ' . $this->end->toString();
}
function getDuration()
{
return $this->end->getStamp() - $this->start->getStamp();
}
function getStart()
{
return $this->start;
}
function getEnd()
{
return $this->end;
}
function isEqual($period)
{
return $this->start->isEqual($period->getStart()) &&
$this->end->isEqual($period->getEnd());
}
function includes($period)
{
return ($this->start->isBefore($period->getStart()) &&
$this->end->isAfter($period->getEnd()));
}
function isInside($period)
{
return $period->includes($this);
}
function intersects($period)
{
return $this->isEqual($period)
||
($this->start->isBefore($period->getStart()) && $this->end->isAfter($period->getStart()))
||
($this->start->isAfter($period->getStart()) && $this->start->isBefore($period->getEnd()));
}
}