DateTime.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace Zend\Stdlib;
  10. use DateTimeZone;
  11. trigger_error('DateTime extension deprecated as of ZF 2.1.4; use the \DateTime constructor to parse extended ISO8601 dates instead', E_USER_DEPRECATED);
  12. /**
  13. * DateTime
  14. *
  15. * An extension of the \DateTime object.
  16. *
  17. * @deprecated
  18. */
  19. class DateTime extends \DateTime
  20. {
  21. /**
  22. * The DateTime::ISO8601 constant used by php's native DateTime object does
  23. * not allow for fractions of a second. This function better handles ISO8601
  24. * formatted date strings.
  25. *
  26. * @param string $time
  27. * @param DateTimeZone $timezone
  28. * @return mixed
  29. */
  30. public static function createFromISO8601($time, DateTimeZone $timezone = null)
  31. {
  32. $format = self::ISO8601;
  33. if (isset($time[19]) && $time[19] === '.') {
  34. $format = 'Y-m-d\TH:i:s.uO';
  35. }
  36. if ($timezone !== null) {
  37. return self::createFromFormat($format, $time, $timezone);
  38. }
  39. return self::createFromFormat($format, $time);
  40. }
  41. }