feat(dashboard): implement Jalali month start calculation and add related tests

This commit is contained in:
hamed
2026-08-04 20:31:08 +03:30
parent df8a43f8b2
commit 9d767a6c63
4 changed files with 240 additions and 24 deletions
@@ -57,7 +57,7 @@ class DashboardController extends BaseController
$clinicId = $clinic->getId();
$todayStart = strtotime('today midnight');
$todayEnd = strtotime('tomorrow midnight') - 1;
$monthStart = strtotime('first day of this month midnight');
$monthStart = $this->currentJalaliMonthStart();
$from = $request->query->get('from') ? (int) $request->query->get('from') : $monthStart;
$to = $request->query->get('to') ? (int) $request->query->get('to') : time();
@@ -214,7 +214,7 @@ class DashboardController extends BaseController
$todayEnd = strtotime('tomorrow midnight') - 1;
$tmrStart = strtotime('tomorrow midnight');
$tmrEnd = strtotime('tomorrow midnight') + 86399;
$monthStart = strtotime('first day of this month midnight');
$monthStart = $this->currentJalaliMonthStart();
$from = $request->query->get('from') ? (int) $request->query->get('from') : $monthStart;
$to = $request->query->get('to') ? (int) $request->query->get('to') : time();
@@ -404,6 +404,20 @@ class DashboardController extends BaseController
];
}
/**
* آغاز ماه شمسی جاری.
*
* «این ماه» در محصولی که تقویمش شمسی است یعنی ماه شمسی، نه گرگوری. با
* `strtotime('first day of this month')` آمارِ داشبورد اولِ ژانویه/فوریه/… صفر
* می‌شد — وسط مرداد یا آبان — و هیچ‌کجای پنل چنین مرزی را نشان نمی‌دهد.
*/
private function currentJalaliMonthStart(): int
{
[$year, $month] = $this->currentJalaliYearMonth();
return $this->jalaliMonthRange($year, $month)['start'];
}
/**
* بازه‌ی یونیکس یک ماه شمسی و تعداد روزهای آن.
* @return array{start:int, end:int, days:int}