1
0

DateTimeHelper.php 536 B

1234567891011121314151617181920212223
  1. <?php
  2. namespace fphammerle\helpers;
  3. class DateTimeHelper
  4. {
  5. /**
  6. * @param integer|null $timestamp unix timestamp
  7. * @return DateTime|null
  8. */
  9. public static function timestampToDateTime($timestamp)
  10. {
  11. if($timestamp === null) {
  12. return null;
  13. } elseif(is_int($timestamp)) {
  14. $dt = new \DateTime();
  15. $dt->setTimestamp($timestamp);
  16. return $dt;
  17. } else {
  18. throw new \InvalidArgumentException('expected integer or null');
  19. }
  20. }
  21. }