Skip to content

Commit e0307ef

Browse files
committed
Minor adjustments.
1 parent 84eab91 commit e0307ef

File tree

3 files changed

+51
-23
lines changed

3 files changed

+51
-23
lines changed

config/config.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

33
/**
4-
* This configuration file defines the calendar table name, start months for each season and the start month of the fiscal year.
5-
*
6-
* @return array
4+
* Configuration file for the Laravel Calendar Table package.
75
*/
86
return [
97
/**
@@ -13,7 +11,18 @@
1311

1412
/**
1513
* The 'seasons' array defines the start month for each season.
16-
* Each key is a season name, and each value is the start month for that season.
14+
*
15+
* This configuration assumes the meteorological seasons of the Northern Hemisphere, where the seasons are defined as follows:
16+
* - Spring starts in March (3rd month)
17+
* - Summer starts in June (6th month)
18+
* - Autumn starts in September (9th month)
19+
* - Winter starts in December (12th month)
20+
*
21+
* Users in the Southern Hemisphere should reconfigure the seasons approximately six months offset from those of the Northern Hemisphere:
22+
* - Spring starts in September
23+
* - Summer starts in December
24+
* - Autumn starts in March
25+
* - Winter starts in June
1726
*/
1827
'seasons' => [
1928
'Spring' => 3,
@@ -23,7 +32,13 @@
2332
],
2433

2534
/**
26-
* The 'fiscal_year_start_month' defines the start month of the fiscal year.
35+
* The 'fiscal_year_start_month' option defines the start month of the fiscal year.
36+
*
37+
* Months are represented as numbers between 1 (January) and 12 (December).
38+
*
39+
* In this case, the fiscal year starts in October (10th month). This might be the case for a company or government that operates on a fiscal year that begins on October 1 and ends on September 30 of the following year.
40+
*
41+
* Users should adjust this setting to match their own fiscal year. For example, if the fiscal year starts in July, they would set this option to 7.
2742
*/
2843
'fiscal_year_start_month' => 10,
2944
];

phpstan-baseline.neon

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
11
parameters:
2-
ignoreErrors:
3-
-
4-
message: "#^Unable to resolve the template type TKey in call to function collect$#"
5-
count: 1
6-
path: src/Commands/CalendarTableCommand.php
7-
8-
-
9-
message: "#^Unable to resolve the template type TValue in call to function collect$#"
10-
count: 1
11-
path: src/Commands/CalendarTableCommand.php
2+
ignoreErrors: []

src/Commands/CalendarTableCommand.php

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct()
3939
{
4040
parent::__construct();
4141

42-
$this->tableName = config('calendar-table.table_name','date_dimension');
42+
$this->tableName = config('calendar-table.table_name', 'date_dimension');
4343
}
4444

4545
/**
@@ -181,22 +181,44 @@ public function isValidYear(int $input)
181181
/**
182182
* Determines the season for a given date.
183183
*
184+
* This function determines the season for a given date based on the start month of each season.
185+
* The function iterates through the seasons array and returns the first season where the start month is less than or equal to the current month.
186+
* If no season is found, the function returns 'Winter' as the default season.
184187
*
185-
* @throws \Exception If the 'seasons' configuration is not set.
188+
* @param Carbon $date The date for which the season is to be determined.
189+
* @return string The season for the given date.
186190
*/
187191
public function determineSeason(Carbon $date): string
188192
{
189-
// Determine the season
190-
return collect(config('calendar-table.seasons'), [])->filter(function ($startMonth) use ($date) {
191-
return $date->month >= $startMonth;
192-
})->keys()->last() ?? 'Winter';
193+
$seasons = config('calendar-table.seasons', [
194+
'Spring' => 3,
195+
'Summer' => 6,
196+
'Autumn' => 9,
197+
'Winter' => 12,
198+
]);
199+
200+
// Reverse the seasons array so we can find the first season where the start month is less than or equal to the current month
201+
$seasons = array_reverse($seasons, true);
202+
203+
foreach ($seasons as $season => $startMonth) {
204+
if ($date->month >= $startMonth) {
205+
return $season;
206+
}
207+
}
208+
209+
return 'Winter';
193210
}
194211

195212
/**
196-
* Calculates the fiscal year and quarter for a given date.
213+
* Determines the fiscal year and quarter for a given date.
197214
*
215+
* This function determines the fiscal year and quarter for a given date based on the start month of the fiscal year.
216+
* The function calculates the fiscal year based on the month of the date and the start month of the fiscal year.
217+
* If the month of the date is greater than or equal to the start month of the fiscal year, the fiscal year is incremented by 1.
218+
* The fiscal quarter is calculated based on the month of the date and the start month of the fiscal year.
198219
*
199-
* @throws \Exception If the 'fiscal_year_start_month' configuration is not set.
220+
* @param Carbon $date The date for which the fiscal year and quarter are to be determined.
221+
* @return array An array containing the fiscal year and quarter for the given date.
200222
*/
201223
public function fiscalYearQuarter(Carbon $date): array
202224
{

0 commit comments

Comments
 (0)