Skip to content

Commit

Permalink
Use Month enum internally where appropriate.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnutix committed Mar 30, 2024
1 parent 9e8971b commit c739ba8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Field/WeekOfYear.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Brick\DateTime\DateTimeException;
use Brick\DateTime\DayOfWeek;
use Brick\DateTime\LocalDate;
use Brick\DateTime\Month;

/**
* The week-of-year field.
Expand Down Expand Up @@ -51,7 +52,7 @@ public static function check(int $weekOfYear, ?int $year = null): void
*/
public static function is53WeekYear(int $year): bool
{
$date = LocalDate::of($year, 1, 1);
$date = LocalDate::of($year, Month::JANUARY, 1);
$dayOfWeek = $date->getDayOfWeek();

return $dayOfWeek === DayOfWeek::THURSDAY
Expand Down
6 changes: 3 additions & 3 deletions src/LocalDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static function ofYearDay(int $year, int $dayOfYear): LocalDate

$dayOfMonth = $dayOfYear - $monthOfYear->getFirstDayOfYear($isLeap) + 1;

return LocalDate::of($year, $monthOfYear->value, $dayOfMonth);
return LocalDate::of($year, $monthOfYear, $dayOfMonth);
}

/**
Expand Down Expand Up @@ -223,7 +223,7 @@ public static function min(): LocalDate
return $min;
}

return $min = LocalDate::of(self::MIN_YEAR, 1, 1);
return $min = LocalDate::of(self::MIN_YEAR, Month::JANUARY, 1);
}

/**
Expand All @@ -240,7 +240,7 @@ public static function max(): LocalDate
return $max;
}

return $max = LocalDate::of(self::MAX_YEAR, 12, 31);
return $max = LocalDate::of(self::MAX_YEAR, Month::DECEMBER, 31);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/LocalTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ public function toSecondOfDay(): int
*/
public function toNativeDateTime(): DateTime
{
return $this->atDate(LocalDate::of(0, 1, 1))->toNativeDateTime();
return $this->atDate(LocalDate::of(0, Month::JANUARY, 1))->toNativeDateTime();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Year.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ public function atMonthDay(MonthDay $monthDay): LocalDate
public function toLocalDateRange(): LocalDateRange
{
return LocalDateRange::of(
$this->atMonth(1)->getFirstDay(),
$this->atMonth(12)->getLastDay(),
$this->atMonth(Month::JANUARY)->getFirstDay(),
$this->atMonth(Month::DECEMBER)->getLastDay(),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/YearWeek.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function atDay(DayOfWeek|int $dayOfWeek): LocalDate
$dayOfWeek = DayOfWeek::from($dayOfWeek);
}

$correction = LocalDate::of($this->year, 1, 4)->getDayOfWeek()->value + 3;
$correction = LocalDate::of($this->year, Month::JANUARY, 4)->getDayOfWeek()->value + 3;
$dayOfYear = $this->week * 7 + $dayOfWeek->value - $correction;
$maxDaysOfYear = Field\Year::isLeap($this->year) ? 366 : 365;

Expand Down

0 comments on commit c739ba8

Please sign in to comment.