From 9085d9cad39cec80a9269f9432bb38409009eabc Mon Sep 17 00:00:00 2001 From: Kieffer Navarro Date: Wed, 30 Nov 2022 09:59:11 +0800 Subject: [PATCH 1/3] updated strftime and carbon --- composer.json | 2 +- src/Helpers/CalendarUtil.php | 42 +++++++++++++++---------------- src/Models/RecurringDayOfWeek.php | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index 7a60e84..e0fc159 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require": { "silverstripe/cms": "^4", "johngrogg/ics-parser": "^2", - "nesbot/carbon": "1.39.1" + "nesbot/carbon": "^2" }, "support": { "issues": "https://github.com/unclecheese/silverstripe-event-calendar/issues" diff --git a/src/Helpers/CalendarUtil.php b/src/Helpers/CalendarUtil.php index d7d583e..691629f 100644 --- a/src/Helpers/CalendarUtil.php +++ b/src/Helpers/CalendarUtil.php @@ -50,26 +50,26 @@ class CalendarUtil public static function format_character_replacements($start, $end) { return [ - strftime('%a', $start), - strftime('%A', $start), + date('D', $start), + date('l'. $start), date ('j', $start), date ('d', $start), date ('S', $start), date ('n', $start), date ('m', $start), - strftime('%b', $start), - strftime('%B', $start), + date('M', $start), + date('F', $start), date ('y', $start), date ('Y', $start), - strftime('%a', $end), - strftime('%A', $end), + date('D', $end), + date('l'. $end), date ('j', $end), date ('d', $end), date ('S', $end), date ('n', $end), date ('m', $end), - strftime('%b', $end), - strftime('%B', $end), + date('M', $end), + date('F', $end), date ('y', $end), date ('Y', $end), ]; @@ -178,21 +178,21 @@ public static function microformat($date, $time, $offset = null) /** * @return array */ - public static function get_months_map($key = '%b') + public static function get_months_map($key = 'M') { return [ - '01' => strftime($key, strtotime('2000-01-01')), - '02' => strftime($key, strtotime('2000-02-01')), - '03' => strftime($key, strtotime('2000-03-01')), - '04' => strftime($key, strtotime('2000-04-01')), - '05' => strftime($key, strtotime('2000-05-01')), - '06' => strftime($key, strtotime('2000-06-01')), - '07' => strftime($key, strtotime('2000-07-01')), - '08' => strftime($key, strtotime('2000-08-01')), - '09' => strftime($key, strtotime('2000-09-01')), - '10' => strftime($key, strtotime('2000-10-01')), - '11' => strftime($key, strtotime('2000-11-01')), - '12' => strftime($key, strtotime('2000-12-01')) + '01' => date($key, strtotime('2000-01-01')), + '02' => date($key, strtotime('2000-02-01')), + '03' => date($key, strtotime('2000-03-01')), + '04' => date($key, strtotime('2000-04-01')), + '05' => date($key, strtotime('2000-05-01')), + '06' => date($key, strtotime('2000-06-01')), + '07' => date($key, strtotime('2000-07-01')), + '08' => date($key, strtotime('2000-08-01')), + '09' => date($key, strtotime('2000-09-01')), + '10' => date($key, strtotime('2000-10-01')), + '11' => date($key, strtotime('2000-11-01')), + '12' => date($key, strtotime('2000-12-01')) ]; } diff --git a/src/Models/RecurringDayOfWeek.php b/src/Models/RecurringDayOfWeek.php index fc64f24..3f85e4e 100644 --- a/src/Models/RecurringDayOfWeek.php +++ b/src/Models/RecurringDayOfWeek.php @@ -63,7 +63,7 @@ public function requireDefaultRecords() public function getTitle() { - return strftime("%a", Carbon::now()->next($this->Value)->getTimestamp()); + return date("D", Carbon::now()->next($this->Value)->getTimestamp()); } From 538f6b1870aed75875b55d5f43e6ccb95bd663eb Mon Sep 17 00:00:00 2001 From: Kieffer Navarro Date: Wed, 30 Nov 2022 10:45:03 +0800 Subject: [PATCH 2/3] updated the get_months_map function --- src/Pages/CalendarController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pages/CalendarController.php b/src/Pages/CalendarController.php index 4e1813d..c297f47 100644 --- a/src/Pages/CalendarController.php +++ b/src/Pages/CalendarController.php @@ -657,7 +657,7 @@ public function MonthJumpForm() $this, __FUNCTION__, FieldList::create( - $m = DropdownField::create('Month','', CalendarUtil::get_months_map('%B')), + $m = DropdownField::create('Month','', CalendarUtil::get_months_map('F')), $y = DropdownField::create('Year','', array_combine($yearRange, $yearRange)) ), FieldList::create( From eacb00e4a3acd05ff88912ecd041b5ca86574d79 Mon Sep 17 00:00:00 2001 From: Kieffer Navarro Date: Wed, 30 Nov 2022 11:05:44 +0800 Subject: [PATCH 3/3] updated strtotime passing null paramters --- src/Helpers/CalendarUtil.php | 8 ++++---- src/Helpers/RecursionReader.php | 2 +- src/Pages/Calendar.php | 4 ++-- src/Pages/CalendarEventController.php | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Helpers/CalendarUtil.php b/src/Helpers/CalendarUtil.php index 691629f..1eff2dd 100644 --- a/src/Helpers/CalendarUtil.php +++ b/src/Helpers/CalendarUtil.php @@ -122,8 +122,8 @@ public static function get_date_string($startDate, $endDate) $strStartDate = null; $strEndDate = null; - $start = strtotime($startDate); - $end = strtotime($endDate); + $start = strtotime($startDate ?? ''); + $end = strtotime($endDate ?? ''); $startYear = date("Y", $start); $startMonth = date("m", $start); @@ -240,12 +240,12 @@ public static function date_sort_callback($a, $b) if ($a->StartDate == $b->StartDate) { if ($a->StartTime == $b->StartTime) { return 0; - } elseif (strtotime($a->StartTime) > strtotime($b->StartTime)) { + } elseif (strtotime($a->StartTime ?? '') > strtotime($b->StartTime ?? '')) { return 1; } return -1; } - elseif (strtotime($a->StartDate) > strtotime($b->StartDate)) { + elseif (strtotime($a->StartDate ?? '') > strtotime($b->StartDate ?? '')) { return 1; } return -1; diff --git a/src/Helpers/RecursionReader.php b/src/Helpers/RecursionReader.php index d70f9c3..cfeb980 100644 --- a/src/Helpers/RecursionReader.php +++ b/src/Helpers/RecursionReader.php @@ -69,7 +69,7 @@ public function __construct(CalendarEvent $event) if ($datetime = DataList::create($this->datetimeClass) ->filter($relation, $event->ID)->first() ) { - $this->ts = strtotime($datetime->StartDate); + $this->ts = strtotime($datetime->StartDate ?? ''); } if ($event->CustomRecursionType == CalendarEvent::RECUR_INTERVAL_WEEKLY) { diff --git a/src/Pages/Calendar.php b/src/Pages/Calendar.php index 3f28595..d54eb49 100644 --- a/src/Pages/Calendar.php +++ b/src/Pages/Calendar.php @@ -462,7 +462,7 @@ public function getNextRecurringEvents($eventObj, $datetimeObj, $limit = null) $counter = Carbon::parse($datetimeObj->StartDate); if ($event = $datetimeObj->Event()->DateTimes()->First()) { - $endDate = strtotime($event->EndDate); + $endDate = strtotime($event->EndDate ?? ''); } else { $endDate = false; } @@ -527,7 +527,7 @@ protected function addRecurringEvents($startDate, $endDate, $recurringEvents, $a } // check the end date if ($recurringEventDatetime->EndDate) { - $endStamp = strtotime($recurringEventDatetime->EndDate); + $endStamp = strtotime($recurringEventDatetime->EndDate ?? ''); if ($endStamp > 0 && $endStamp < $dateCounter->getTimestamp()) { break; } diff --git a/src/Pages/CalendarEventController.php b/src/Pages/CalendarEventController.php index dd62094..621d517 100644 --- a/src/Pages/CalendarEventController.php +++ b/src/Pages/CalendarEventController.php @@ -96,7 +96,7 @@ public function getCurrentDate() return $allDates->first(); } if (strtotime($_REQUEST['date']) > 0) { - $date = date('Y-m-d', strtotime($_REQUEST['date'])); + $date = date('Y-m-d', strtotime($_REQUEST['date'] ?? '')); if ($this->Recursion) { $datetime = $allDates->first(); if ($datetime) {