* @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:----VHYkeeFDP9+YKv2OD71xHG+lolWhMB/Cd7shEls60Sb3PdCXCZIE7DwGC2w34WGYGY3wdVXHxR1OeMFXiISKSenqevAmH8AzfezGsuwTlpleOOdgs+VKqr03Xkwnqa7g3BXQ8/+ixumuc9+EUUFn1t5N5pjC/yw3v0CzfiV6iONUOJ7O7haGcMyDSVLoh6aJLjr8RH2DOwohA/RQ4BfvJ1mzgApVn62gFoyeDn8mEJ4gHoLamJvgDIJ8z2PI0Kdtpe8rOehJxi3E4ukwmC9OCbVAoZZaijeIFqJvq8rvgQPZpiwUKUuoSKC4+3F8oIXge5xhgy4d1qFaJGdquPpPi4CciweDUP6yHNGj2gQ99w5+SSiePMIVCmYfWJFzhDMl5wsSZzyxYatywW/jYnOh+mYOF6pHexshtbk3J2eSAGfNeDb8rBAaw3Os9YIXBzYeZWL5e6jr2fv3EFtT2XLD6N+gvKQJGaPIXdFrWmE6OMxiUpe0OXyYdfiXzYE8lKJFhHOSPHKaHVLmmgWM27Xpd03vUiCb3eA5L4J5/BzWLUUdoiB7nRdwFmpwf4z/i/q4EfrXAn1ILu5RFBwRavsfUqwO3jpvMO/tZpsOSLQiGstTrPNGeQaRIFbNiwQ+ir9abGAdCov1oYUrd/IBFczP59x0obrspB5F2g0i9vm6LGA=----ATTACHMENT:----OTgzMTgwNzg4OTY4NzUxOCA3NTE5MzQyNDcyNTQ4MzkzIDYwODg0ODU3NTQ4ODg3MTM=