DateTimeResult.php 883 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Aws\Api;
  3. /**
  4. * DateTime overrides that make DateTime work more seamlessly as a string,
  5. * with JSON documents, and with JMESPath.
  6. */
  7. class DateTimeResult extends \DateTime implements \JsonSerializable
  8. {
  9. /**
  10. * Create a new DateTimeResult from a unix timestamp.
  11. *
  12. * @param $unixTimestamp
  13. *
  14. * @return DateTimeResult
  15. */
  16. public static function fromEpoch($unixTimestamp)
  17. {
  18. return new self(gmdate('c', $unixTimestamp));
  19. }
  20. /**
  21. * Serialize the DateTimeResult as an ISO 8601 date string.
  22. *
  23. * @return string
  24. */
  25. public function __toString()
  26. {
  27. return $this->format('c');
  28. }
  29. /**
  30. * Serialize the date as an ISO 8601 date when serializing as JSON.
  31. *
  32. * @return mixed|string
  33. */
  34. public function jsonSerialize()
  35. {
  36. return (string) $this;
  37. }
  38. }