xxxxxxxxxx
// Interface definition
interface Vehicle {
void startEngine();
}
// Class that implements the interface
class Car implements Vehicle {
public void startEngine() {
System.out.println("Car engine started.");
}
}
// Usage of the interface
public class Main {
public static void main(String[] args) {
Vehicle myCar = new Car(); // Using the interface type
myCar.startEngine(); // Calling the method
}
}
xxxxxxxxxx
$startdate = \Carbon\Carbon::parse("31-january-2024");
$enddate = \Carbon\Carbon::parse("29-february-2024");
$startdate->diffInMonths($deprperiod); // <-- will returning 0.93548387096774 even the date of $enddate is in end of february month
// im using Laravel
// create carbon macro in AppServiceProvider.php
Carbon::macro('floatDiffInMonthsNoOverflow', static function ($end) {
$start = static::this();
$end = $start->resolveCarbon($end);
$diffInMonths = $start->diffInMonths($end);
$diff = 0;
foreach ($start->daysUntil($end) as $date) {
$diff += 1 / $date->daysInMonth;
}
return $diffInMonths >= $diff ? $diffInMonths : $diff;
});
$startdate->floatDiffInMonthsNoOverflow($deprperiod); // <-- will returning 1.0322580645161