Skip to content

Commit

Permalink
Add some improved logic for date handling, add Kirby version check, r…
Browse files Browse the repository at this point in the history
…esolve Kirby 5 section error, bump version number.
  • Loading branch information
scottboms committed Jan 27, 2025
1 parent 0952ed8 commit 3cacc84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
11 changes: 9 additions & 2 deletions classes/Microseasons.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ public static function getSeason($today, $jsonFileUrl): array {
// convert $today passed to 4-character mmdd format
// since we don't care about the specific year
$timestamp = Date::createFromFormat('Y-m-d', $today);
$currentYear = Date::createFromFormat('Y-m-d', $today)->format('Y');
if(!$timestamp) {
// fallback to the current date if $today is invalid
$today = date('Y-m-d');
$timestamp = Date::createFromFormat('Y-m-d', $today);
}

// safely get the year from the parsed date
$currentYear = $timestamp ? $timestamp->format('Y') : date('Y');

$wrapper = option('scottboms.microseasons.wrapper') ?? 'div';
$class = option('scottboms.microseasons.class') ?? 'microseasons';
Expand Down Expand Up @@ -68,7 +75,7 @@ public static function getSeason($today, $jsonFileUrl): array {
}

public static function convertDateFormat($dateString): string {
$reformattedDate = $dateString->format(option("scottboms.microseasons.dateformat")) ?? $dateString->format('M d');
$reformattedDate = $dateString->format('M d') ?? $dateString->format(option("scottboms.microseasons.dateformat"));
return $reformattedDate;
}
}
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"kirby-plugin"
],
"require": {
"php": ">8.1.0 <8.4.0",
"getkirby/cms": "^4.0 || ^5.0",
"getkirby/composer-installer": "^1.1"
},
"extra": {
Expand Down
9 changes: 8 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@

use Scottboms\Microseasons\Season;
use Kirby\Toolkit\Date;
use Composer\Semver\Semver;
use Kirby\Cms\App as Kirby;

// validate Kirby version
if (Semver::satisfies(Kirby::version() ?? '0.0.0', '~4.0 || ~5.0') === false) {
throw new Exception('HTML5 Video Tag requires Kirby 4 or 5');
}

Kirby::plugin(
name: 'scottboms/kirby-microseasons',
info: [
'homepage' => 'https://github.com/scottboms/kirby-microseasons'
],
version: '1.0.7',
version: '1.0.8',
extends: [
'options' => [
'cache' => True,
Expand Down

0 comments on commit 3cacc84

Please sign in to comment.