@@ -9,40 +9,38 @@ public static function getAllSeasons(): string {
99 return __DIR__ . '/../microseasons.json ' ;
1010 }
1111
12- public static function getSeason ($ currentDate , $ jsonFileUrl ): array {
12+ public static function getSeason ($ today , $ jsonFileUrl ): array {
1313 // fetch and decode the JSON data from the external link
1414 $ json = file_get_contents ($ jsonFileUrl );
1515 $ seasonsArray = json_decode ($ json , true );
1616
17- // convert $currentDate passed to 4-character mmdd format
17+ // convert $today passed to 4-character mmdd format
1818 // since we don't care about the specific year
19- $ timestamp = date ( " m-d " , strtotime ( $ currentDate ) );
19+ $ timestamp = Date:: createFromFormat ( ' Y- m-d' , $ today );
2020
2121 // create $currentSeason to hold an array of data to return
2222 $ currentSeason = array ();
2323
2424 // check which season the current date falls within
2525 foreach ($ seasonsArray as $ season ) {
26- $ start = $ season ["start " ];
27- $ end = $ season ["end " ];
26+ $ start = Date:: createFromFormat ( ' Y-m-d ' , $ season ["start " ]) ;
27+ $ end = Date:: createFromFormat ( ' Y-m-d ' , $ season ["end " ]) ;
2828
2929 // adjust the start and end dates to handle year transitions
3030 if ($ start > $ end ) {
3131 if ($ timestamp >= $ start || $ timestamp < $ end ) {
32- // convert the date information to dates object
33- $ season ["start " ] = Date::createFromFormat ('m-d ' , $ start );
34- $ season ["end " ] = Date::createFromFormat ('m-d ' , $ end );
32+ $ season ['start ' ] = $ start ->format (option ("scottboms.microseasons.dateformat " )) ?? $ start ->format ('M d ' );
33+ $ season ['end ' ] = $ end ->format (option ("scottboms.microseasons.dateformat " )) ?? $ end ->format ('M d ' );
3534 return $ currentSeason [] = $ season ; // return the matching season
3635 }
3736 } else {
3837 if ($ timestamp >= $ start && $ timestamp < $ end ) {
39- $ season [" start " ] = Date:: createFromFormat ( ' m-d ' , $ start );
40- $ season [" end " ] = Date:: createFromFormat ( ' m-d ' , $ end );
38+ $ season [' start ' ] = $ start -> format ( option ( " scottboms.microseasons.dateformat " )) ?? $ start-> format ( ' M d ' );
39+ $ season [' end ' ] = $ end -> format ( option ( " scottboms.microseasons.dateformat " )) ?? $ end-> format ( ' M d ' );
4140 return $ currentSeason [] = $ season ; // return the matching season
4241 }
4342 }
4443 }
45- return $ currentSeason ; // no match fallback
44+ return $ currentSeason ;
4645 }
47-
4846}
0 commit comments