Skip to content

Commit

Permalink
fixed custom date range
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Dec 22, 2023
1 parent 250abe0 commit 949adb4
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions app/Traits/DateTime.php
Expand Up @@ -152,7 +152,13 @@ public function getFinancialWeeks($year = null): array

$start = $this->getFinancialStart($year);

for ($i = 0; $i < 52; $i++) {
$w = 52;

if (request()->filled('start_date') && request()->filled('end_date')) {
$w = Date::parse(request('start_date'))->diffInWeeks(Date::parse(request('end_date'))) + 1;
}

for ($i = 0; $i < $w; $i++) {
$weeks[] = CarbonPeriod::create($start->copy()->addWeeks($i), $start->copy()->addWeeks($i + 1)->subDay()->endOfDay());
}

Expand All @@ -165,7 +171,13 @@ public function getFinancialMonths($year = null): array

$start = $this->getFinancialStart($year);

for ($i = 0; $i < 12; $i++) {
$m = 12;

if (request()->filled('start_date') && request()->filled('end_date')) {
$m = Date::parse(request('start_date'))->diffInMonths(Date::parse(request('end_date'))) + 1;
}

for ($i = 0; $i < $m; $i++) {
$months[] = CarbonPeriod::create($start->copy()->addMonths($i), $start->copy()->addMonths($i + 1)->subDay()->endOfDay());
}

Expand All @@ -178,7 +190,13 @@ public function getFinancialQuarters($year = null): array

$start = $this->getFinancialStart($year);

for ($i = 0; $i < 4; $i++) {
$q = 4;

if (request()->filled('start_date') && request()->filled('end_date')) {
$q = Date::parse(request('start_date'))->diffInQuarters(Date::parse(request('end_date'))) + 1;
}

for ($i = 0; $i < $q; $i++) {
$quarters[] = CarbonPeriod::create($start->copy()->addQuarters($i), $start->copy()->addQuarters($i + 1)->subDay()->endOfDay());
}

Expand Down Expand Up @@ -262,6 +280,8 @@ public function getYearlyDateFormat(): string

public function getPeriodicDate(Date $date, string $period, string $year): string
{
$formatted_date = '';

switch ($period) {
case 'yearly':
$financial_year = $this->getFinancialYear($year);
Expand All @@ -287,6 +307,8 @@ public function getPeriodicDate(Date $date, string $period, string $year): strin
$end = $quarter->copy()->getEndDate()->format($this->getQuarterlyDateFormat($year));

$formatted_date = $start . ' - ' . $end;

break;
}

break;
Expand All @@ -302,6 +324,8 @@ public function getPeriodicDate(Date $date, string $period, string $year): strin
$end = $week->copy()->getEndDate()->format($this->getDailyDateFormat($year));

$formatted_date = $start . ' - ' . $end;

break;
}

break;
Expand Down

0 comments on commit 949adb4

Please sign in to comment.