DayOfYearTransformer.php 987 B

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