The error message suggests that the timestamp generated by the Jalalian::forge() method is not within the expected range. One possible reason for this could be an incorrect date format being passed to the method.
To fix this issue, we can try to debug the input date and the generated timestamp. We can modify the code as follows:
public function store(Product $product, Warranty $warranty, Request $request)
{
$date = $request->post('new_date');
$timestamp = Jalalian::forge($date)->getTimestamp();
dd($date, $timestamp);
}
This will output the input date and the generated timestamp. We can then check if the input date is in the correct format and if the generated timestamp is within the expected range.
If the input date is not in the correct format, we can modify it using the Carbon library, which is a dependency of the Jalali package. For example, if the input date is in the format dd/mm/yyyy, we can modify it as follows:
use Morilog\Jalali\Jalalian;
use Carbon\Carbon;
public function store(Product $product, Warranty $warranty, Request $request)
{
$date = $request->post('new_date');
$carbonDate = Carbon::createFromFormat('d/m/Y', $date);
$jalaliDate = Jalalian::fromCarbon($carbonDate);
$timestamp = $jalaliDate->getTimestamp();
dd($date, $timestamp);
}
This will convert the input date to a Carbon object, which can then be converted to a Jalali object using the fromCarbon() method. We can then get the timestamp from the Jalali object.
If the generated timestamp is not within the expected range, we can check if the input date is correct and if the timezone is set correctly. We can set the timezone using the Jalalian::setLocale() method. For example, if we want to set the timezone to Asia/Tehran, we can modify the code as follows:
use Morilog\Jalali\Jalalian;
use Carbon\Carbon;
public function store(Product $product, Warranty $warranty, Request $request)
{
$date = $request->post('new_date');
$carbonDate = Carbon::createFromFormat('d/m/Y', $date);
$jalaliDate = Jalalian::fromCarbon($carbonDate);
Jalalian::setLocale('fa');
Jalalian::setTimezone('Asia/Tehran');
$timestamp = $jalaliDate->getTimestamp();
dd($date, $timestamp);
}
This will set the timezone to Asia/Tehran and the locale to fa (Farsi), which is the default locale for the Jalali package. We can then get the timestamp from the Jalali object.
Note: The Jalali package requires the intl extension to be installed on the server. If the extension is not installed, the package will not work.