1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 
<?php
namespace Omeka\Stdlib;

use JsonSerializable;

/**
 * A wrapper of PHP's DateTime that can be serialized as JSON.
 */
class DateTime implements JsonSerializable
{
    /**
     * @var PhpDateTime
     */
    protected $dateTime;

    /**
     * @param \DateTime|null $dateTime Null will set the current DateTime
     */
    public function __construct(\DateTime $dateTime = null)
    {
        if (null === $dateTime) {
            // Set current date and time
            $dateTime = new \DateTime;
        }
        $this->dateTime = $dateTime;
    }

    /**
     * Get the underlying DateTime instance.
     *
     * @return \DateTime
     */
    public function getDateTime()
    {
        return $this->dateTime;
    }

    /**
     * Serialize DateTime as an ISO 8601 date.
     *
     * @return string
     */
    public function jsonSerialize()
    {
        return $this->dateTime->format('c');
    }
}