Closed Ali031 closed 5 years ago
i mean how to find start day of current month in carbon is carbon::now()->startOfMonth();
There is not any function for startOfMonth directly. but you can use functions of jDateTime class for getting current month. BTW this lib is not for manipulating date time or something like carbon. the main functionality of this lib is converting Gregorian datetime to Jalali datetime.
Hey there @morilog, sorry to bring up this closed issue but I think adding getStartOfMonth and getEndOfMonth would be beneficial for many people (including myself :) ).
However I wrote this code to use in my current project:
public static function getStartOfMonth(Carbon $dt = null) : Jalalian
{
if (!$dt) {
$dt = now();
}
$jdt = jdate($dt);
return new Jalalian($jdt->getYear(), $jdt->getMonth(), 1, $jdt->getHour(), $jdt->getMinute(), $jdt->getSecond(), $jdt->getTimezone());
}
public static function getEndOfMonth(Carbon $dt = null) : Jalalian
{
if (!$dt) {
$dt = now();
}
$jdt = jdate($dt);
if ($jdt->isLeapYear() && $jdt->getMonth() === 12) {
$lastDayOfCurrentMonth = 29;
}else{
$lastDayOfCurrentMonth = $jdt->getMonth() > 6 ? 30 : 31;
}
return new Jalalian($jdt->getYear(), $jdt->getMonth(), $lastDayOfCurrentMonth, $jdt->getHour(), $jdt->getMinute(), $jdt->getSecond(), $jdt->getTimezone());
}
(I could also help with a PR)
return new Jalalian($jdt->getYear(), $jdt->getMonth(), 1, $jdt->getHour(), $jdt->getMinute(), $jdt->getSecond(), $jdt->getTimezone());
}
This is not the start of the month. the start hours, minutes and, seconds of month should be 00
Start week day of month? or what? please give me some description.