MinuteTransformer.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\Polyfill\Intl\Icu\DateFormat;
  11. /**
  12. * Parser and formatter for minute format.
  13. *
  14. * @author Igor Wiedler <igor@wiedler.ch>
  15. *
  16. * @internal
  17. */
  18. class MinuteTransformer extends Transformer
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function format(\DateTime $dateTime, int $length): string
  24. {
  25. $minuteOfHour = (int) $dateTime->format('i');
  26. return $this->padLeft($minuteOfHour, $length);
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function getReverseMatchingRegExp(int $length): string
  32. {
  33. return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function extractDateOptions(string $matched, int $length): array
  39. {
  40. return [
  41. 'minute' => (int) $matched,
  42. ];
  43. }
  44. }