diff --git a/src/action/UsageInterval.php b/src/action/UsageInterval.php index a1280d9f..4f4fba0a 100644 --- a/src/action/UsageInterval.php +++ b/src/action/UsageInterval.php @@ -110,9 +110,9 @@ public static function withMonthAndFraction( if ($fractionOfMonth === 1.0) { $effectiveTill = $month->modify('+1 month'); } else { - $monthDays = (int) $month->format('t'); - $days = (int) round($monthDays * $fractionOfMonth); - $effectiveTill = $effectiveSince->modify(sprintf('+%d days', $days)); + $interval = new self($month, $nextMonth); + $seconds = $interval->secondsInMonth() * $fractionOfMonth; + $effectiveTill = $effectiveSince->modify(sprintf('+%d seconds', $seconds)); } return new self( diff --git a/tests/unit/action/UsageIntervalTest.php b/tests/unit/action/UsageIntervalTest.php index e8224af0..911654e2 100644 --- a/tests/unit/action/UsageIntervalTest.php +++ b/tests/unit/action/UsageIntervalTest.php @@ -227,9 +227,9 @@ public function provideWithMonthAndFraction() [ 'start' => '2024-02-01 11:50:00', 'end' => '2024-02-29 18:15:00', - 'ratioOfMonth' => 0.97473659003831, - 'seconds' => 2_419_200, - 'secondsInMonth' => 2_419_200, + 'ratioOfMonth' => 0.9747365900383141, + 'seconds' => 2_442_300, + 'secondsInMonth' => 2_505_600, ] ]; }