12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- /**
- * Created by PhpStorm.
- * User: robin
- * Date: 6/14/16
- * Time: 11:46 AM
- */
-
- namespace Luticate\Utils\Dbo;
-
- use Carbon\Carbon;
- use Luticate\Utils\Business\LuStringUtils;
-
- class LuDateTimeDbo extends LuDbo
- {
- /**
- * @var $_value Carbon
- */
- private $_value;
-
- /**
- * @return Carbon
- */
- public function getDateTime()
- {
- return $this->_value;
- }
-
- /**
- * @param Carbon $value
- */
- public function setDateTime($value)
- {
- $this->_value = $value;
- }
-
- function jsonSerialize()
- {
- return is_null($this->_value) ? null : $this->_value->__toString();
- }
-
- public static function jsonDeserialize($json)
- {
- if (is_string($json)) {
- $value = LuStringUtils::parseDate($json);
- if (is_null($value)) {
- throw new LuDboDeserializeException("Invalid date time value");
- }
- }
- else if (is_null($json)) {
- $value = null;
- }
- else {
- throw new LuDboDeserializeException("Invalid date time value");
- }
-
- $val = new static();
- $val->setDateTime($value);
- return $val;
- }
-
- public static function generateSample()
- {
- $date = Carbon::now();
- return $date->__toString();
- }
- }
|