2009-12-18 12:56:12 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright 2009 City of Bloomington, Indiana
|
2011-06-14 13:29:37 +00:00
|
|
|
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
2009-12-18 12:56:12 +00:00
|
|
|
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
|
|
|
*/
|
|
|
|
class Date extends DateTime
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handles array dates passed in the constructor.
|
|
|
|
*
|
|
|
|
* Wrapper for DateTime constructor. If arrays are passed, they will be
|
|
|
|
* handled here. Anything else will be passed to the DateTime constructor.
|
|
|
|
* Arrays should be in the form of PHP's getdate() array
|
|
|
|
*
|
|
|
|
* @param array $date
|
|
|
|
*/
|
|
|
|
public function __construct($date=null)
|
|
|
|
{
|
|
|
|
if (is_array($date)) {
|
|
|
|
if ($date['year'] && $date['mon'] && $date['mday']) {
|
|
|
|
$dateString = "$date[year]-$date[mon]-$date[mday]";
|
|
|
|
|
|
|
|
if (isset($date['hours']) || isset($date['minutes']) || isset($date['seconds'])) {
|
|
|
|
$time = (isset($date['hours']) && $date['hours']) ? "$date[hours]:" : '00:';
|
|
|
|
$time.= (isset($date['minutes']) && $date['minutes']) ? "$date[minutes]:" : '00:';
|
|
|
|
$time.= (isset($date['seconds']) && $date['seconds']) ? $date['seconds'] : '00';
|
|
|
|
|
|
|
|
$dateString.= " $time";
|
|
|
|
}
|
|
|
|
$date = $dateString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_int($date)) {
|
|
|
|
$date = date('Y-m-d',$date);
|
|
|
|
}
|
|
|
|
if (!$date instanceof DateTime) {
|
|
|
|
parent::__construct($date);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return $this->format('n/j/Y');
|
|
|
|
}
|
|
|
|
}
|