You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuDateTimeDbo.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: robin
  5. * Date: 6/14/16
  6. * Time: 11:46 AM
  7. */
  8. namespace Luticate\Utils\Dbo;
  9. use Carbon\Carbon;
  10. use Luticate\Utils\Business\LuStringUtils;
  11. class LuDateTimeDbo extends LuDbo
  12. {
  13. /**
  14. * @var $_value Carbon
  15. */
  16. private $_value;
  17. /**
  18. * @return Carbon
  19. */
  20. public function getDateTime()
  21. {
  22. return $this->_value;
  23. }
  24. /**
  25. * @param Carbon $value
  26. */
  27. public function setDateTime($value)
  28. {
  29. $this->_value = $value;
  30. }
  31. function jsonSerialize()
  32. {
  33. return is_null($this->_value) ? null : $this->_value->__toString();
  34. }
  35. public static function jsonDeserialize($json)
  36. {
  37. if (is_string($json)) {
  38. $value = LuStringUtils::parseDate($json);
  39. if (is_null($value)) {
  40. throw new LuDboDeserializeException("Invalid date time value");
  41. }
  42. }
  43. else if (is_null($json)) {
  44. $value = null;
  45. }
  46. else {
  47. throw new LuDboDeserializeException("Invalid date time value");
  48. }
  49. $val = new static();
  50. $val->setDateTime($value);
  51. return $val;
  52. }
  53. public static function generateSample()
  54. {
  55. $date = Carbon::now();
  56. return $date->__toString();
  57. }
  58. }