* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org * @see http://tools.ietf.org/html/rfc3339#section-5.6 */ class Date extends \DateTime implements \JsonSerializable { protected $year; protected $month; protected $day; public function __construct($date, $month = null, $day = null) { if (func_num_args() == 1) { parent::__construct($this->validate($date)); } else { parent::__construct('@' . gmmktime(0, 0, 0, $month, $day, $date)); } } public function getYear() { return (int) $this->format('Y'); } public function getMonth() { return (int) $this->format('m'); } public function getDay() { return (int) $this->format('d'); } public function toString() { $date = $this->format('Y-m-d'); $offset = $this->getOffset(); if ($offset != 0) { $date.= DateTime::getOffsetBySeconds($offset); } return $date; } public function __toString() { return $this->toString(); } public function jsonSerialize() { return $this->toString(); } protected function validate($date) { $date = (string) $date; $result = preg_match('/^' . self::getPattern() . '$/', $date); if (!$result) { throw new InvalidArgumentException('Must be valid date format'); } return $date; } public static function fromDateTime(\DateTime $date) { return new self($date->format('Y'), $date->format('m'), $date->format('d')); } /** * @see http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/datatypes.html#date-lexical-mapping */ public static function getPattern() { return '-?([1-9][0-9]{3,}|0[0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(Z|(\+|-)((0[0-9]|1[0-3]):([0-5][0-9]|14:00)))?'; } } __halt_compiler();----SIGNATURE:----wP6IkP696sqDyXU0zThG5oFxAIqPqn0h1CW+wL6ppLfp71c+VimsJx/L6gdNrxXvYuyX5b6mrmyp/ILFuoFqdSBCn+TLxSMpsOG2vQi2xSqpGDvb6cI/rRmhz81+AkVqu7nvcQsAoM5qEv1FlsxXRCbDqHg5/3H4UlHWpRtnH2LTulKjX1e3AeZ54vmhhbNhLb/cGnL1eyjBz1165ixRcVKkWRc6Rm2YpGek7QVuWrX5M6Soqfn3K+Z55n/7RXGUlXJlZNdI6jirBu7hpAXfE4i56rNzvLVCegUrYTFXWtPshlr4nuV/k1RV3A3+63xu7picnXk9qv55odhIYO/adfYz5d0u7VQZ5gIyjr7u9p2CY+DGcoXJqqNplt/n5x5IHIdJ13WUAPpIEQ9H/2J5IPLh5avvJnLxfGqmsULul3uxlHqlWnkHiIZslvlXlDPonQOFHeQ4y4ouCOkPHdA0ObFUw/O17VkloQHcvgnz0gfFYGHvnEUHeJ6GcTzwiJOGHmvWPj0SsD1gIADEQOfdoGKbUfyXkBON8KILhvAoDC97J1n6U0Se/vBOqXB5ne5MRkEdFpFNSM6sAISmKbymnDJQN9mkCS2llHAcWHz/b1AS1DjkK5/nlYwKjY7R7Z+UzbndpOpWqJAkcTwC+yGqBxU+5DF4CgYNwNg06yhisdo=----ATTACHMENT:----MzQwNTgyNjE1MTE5MTE4OCA4ODYyMTE5MTAyNTQxODMxIDI2MzM4NjMxMDA4ODMyMA==