Mixin.php 910 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of the Carbon package.
  5. *
  6. * (c) Brian Nesbitt <brian@nesbot.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Tests\CarbonImmutable\Fixtures;
  12. use Carbon\CarbonImmutable;
  13. class Mixin
  14. {
  15. public $timezone;
  16. public function setUserTimezone()
  17. {
  18. $mixin = $this;
  19. return function ($timezone) use ($mixin) {
  20. $mixin->timezone = $timezone;
  21. };
  22. }
  23. public function userFormat()
  24. {
  25. $mixin = $this;
  26. return function ($format) use ($mixin) {
  27. /** @var CarbonImmutable $date */
  28. $date = $this;
  29. if ($mixin->timezone) {
  30. $date = $date->setTimezone($mixin->timezone);
  31. }
  32. return $date->format($format);
  33. };
  34. }
  35. }