You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DayOfMonth.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace App\Enums\Accounting;
  3. use App\Enums\Concerns\ParsesEnum;
  4. use Carbon\CarbonImmutable;
  5. use Filament\Support\Contracts\HasLabel;
  6. use Illuminate\Support\Carbon;
  7. enum DayOfMonth: int implements HasLabel
  8. {
  9. use ParsesEnum;
  10. case First = 1;
  11. case Last = -1;
  12. case Second = 2;
  13. case Third = 3;
  14. case Fourth = 4;
  15. case Fifth = 5;
  16. case Sixth = 6;
  17. case Seventh = 7;
  18. case Eighth = 8;
  19. case Ninth = 9;
  20. case Tenth = 10;
  21. case Eleventh = 11;
  22. case Twelfth = 12;
  23. case Thirteenth = 13;
  24. case Fourteenth = 14;
  25. case Fifteenth = 15;
  26. case Sixteenth = 16;
  27. case Seventeenth = 17;
  28. case Eighteenth = 18;
  29. case Nineteenth = 19;
  30. case Twentieth = 20;
  31. case TwentyFirst = 21;
  32. case TwentySecond = 22;
  33. case TwentyThird = 23;
  34. case TwentyFourth = 24;
  35. case TwentyFifth = 25;
  36. case TwentySixth = 26;
  37. case TwentySeventh = 27;
  38. case TwentyEighth = 28;
  39. case TwentyNinth = 29;
  40. case Thirtieth = 30;
  41. case ThirtyFirst = 31;
  42. public function getLabel(): ?string
  43. {
  44. return match ($this) {
  45. self::First => 'First',
  46. self::Last => 'Last',
  47. self::Second => '2nd',
  48. self::Third => '3rd',
  49. self::Fourth => '4th',
  50. self::Fifth => '5th',
  51. self::Sixth => '6th',
  52. self::Seventh => '7th',
  53. self::Eighth => '8th',
  54. self::Ninth => '9th',
  55. self::Tenth => '10th',
  56. self::Eleventh => '11th',
  57. self::Twelfth => '12th',
  58. self::Thirteenth => '13th',
  59. self::Fourteenth => '14th',
  60. self::Fifteenth => '15th',
  61. self::Sixteenth => '16th',
  62. self::Seventeenth => '17th',
  63. self::Eighteenth => '18th',
  64. self::Nineteenth => '19th',
  65. self::Twentieth => '20th',
  66. self::TwentyFirst => '21st',
  67. self::TwentySecond => '22nd',
  68. self::TwentyThird => '23rd',
  69. self::TwentyFourth => '24th',
  70. self::TwentyFifth => '25th',
  71. self::TwentySixth => '26th',
  72. self::TwentySeventh => '27th',
  73. self::TwentyEighth => '28th',
  74. self::TwentyNinth => '29th',
  75. self::Thirtieth => '30th',
  76. self::ThirtyFirst => '31st',
  77. };
  78. }
  79. public function isFirst(): bool
  80. {
  81. return $this === self::First;
  82. }
  83. public function isLast(): bool
  84. {
  85. return $this === self::Last;
  86. }
  87. public function resolveDate(Carbon | CarbonImmutable $date): Carbon | CarbonImmutable
  88. {
  89. if ($this->isLast()) {
  90. return $date->endOfMonth();
  91. }
  92. return $date->day(min($this->value, $date->daysInMonth));
  93. }
  94. public function mayExceedMonthLength(): bool
  95. {
  96. return $this->value > 28;
  97. }
  98. }