JenssegersDate.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\Jenssegers;
  12. use Carbon\Carbon;
  13. class JenssegersDate extends Carbon
  14. {
  15. /**
  16. * Function to call instead of format.
  17. *
  18. * @var string|callable|null
  19. */
  20. protected static $formatFunction = 'jngFormat';
  21. /**
  22. * Function to call instead of createFromFormat.
  23. *
  24. * @var string|callable|null
  25. */
  26. protected static $createFromFormatFunction = 'jngCreateFromFormat';
  27. /**
  28. * Function to call instead of parse.
  29. *
  30. * @var string|callable|null
  31. */
  32. protected static $parseFunction = 'jngParse';
  33. public static function jngParse($time = null, $tz = null)
  34. {
  35. if (\is_string($time)) {
  36. $time = static::translateTimeString($time, static::getLocale(), 'en');
  37. }
  38. return parent::rawParse($time, $tz);
  39. }
  40. public static function jngCreateFromFormat($format, $time = null, $tz = null)
  41. {
  42. if (\is_string($time)) {
  43. $time = static::translateTimeString($time, static::getLocale(), 'en');
  44. }
  45. return parent::rawCreateFromFormat($format, $time, $tz);
  46. }
  47. public function jngFormat($format)
  48. {
  49. return $this->translatedFormat($format);
  50. }
  51. }