DayTransformer.php 942 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Locale\Stub\DateFormat;
  11. /**
  12. * Parser and formatter for day format
  13. *
  14. * @author Igor Wiedler <igor@wiedler.ch>
  15. */
  16. class DayTransformer extends Transformer
  17. {
  18. /**
  19. * {@inheritDoc}
  20. */
  21. public function format(\DateTime $dateTime, $length)
  22. {
  23. return $this->padLeft($dateTime->format('j'), $length);
  24. }
  25. /**
  26. * {@inheritDoc}
  27. */
  28. public function getReverseMatchingRegExp($length)
  29. {
  30. return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
  31. }
  32. /**
  33. * {@inheritDoc}
  34. */
  35. public function extractDateOptions($matched, $length)
  36. {
  37. return array(
  38. 'day' => (int) $matched,
  39. );
  40. }
  41. }