Skip to content

Commit 7cf60c2

Browse files
Hp 2166/store action usage interval in the action table (#88)
1 parent 056abfa commit 7cf60c2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/action/UsageInterval.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ public static function withMonthAndFraction(
110110
if ($fractionOfMonth === 1.0) {
111111
$effectiveTill = $month->modify('+1 month');
112112
} else {
113-
$monthDays = (int) $month->format('t');
114-
$days = (int) round($monthDays * $fractionOfMonth);
115-
$effectiveTill = $effectiveSince->modify(sprintf('+%d days', $days));
113+
$interval = new self($month, $nextMonth);
114+
$seconds = $interval->secondsInMonth() * $fractionOfMonth;
115+
$effectiveTill = $effectiveSince->modify(sprintf('+%d seconds', $seconds));
116116
}
117117

118118
return new self(

tests/unit/action/UsageIntervalTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ public function provideWithMonthAndFraction()
227227
[
228228
'start' => '2024-02-01 11:50:00',
229229
'end' => '2024-02-29 18:15:00',
230-
'ratioOfMonth' => 0.97473659003831,
231-
'seconds' => 2_419_200,
232-
'secondsInMonth' => 2_419_200,
230+
'ratioOfMonth' => 0.9747365900383141,
231+
'seconds' => 2_442_300,
232+
'secondsInMonth' => 2_505_600,
233233
]
234234
];
235235
}

0 commit comments

Comments
 (0)