Skip to content

Commit

Permalink
Fix checking for past event when it is created from different time zone
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed May 1, 2024
1 parent 16bba44 commit 9bedce0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Changelog
=========

Unreleased
------------------------
1.5.11 (Unreleased)
-----------------------
- Enh #473: Add footer to global calendar
- Fix #474: Fix checking for past event when it is created from different time zone

1.5.10 (March 19, 2024)
-----------------------
Expand Down
12 changes: 10 additions & 2 deletions models/CalendarEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace humhub\modules\calendar\models;

use DateTime;
use DateTimeZone;
use humhub\modules\calendar\helpers\CalendarUtils;
use humhub\modules\calendar\helpers\RecurrenceHelper;
use humhub\modules\calendar\helpers\Url;
Expand Down Expand Up @@ -1066,7 +1067,14 @@ public function canInvite(?User $user = null): bool

public function isPast(): bool
{
$timeZone = CalendarUtils::getEndTimeZone($this);
return new DateTime('now', $timeZone) > new DateTime($this->end_datetime ?? 'now', $timeZone);
$currentTimeZone = new DateTimeZone(Yii::$app->timeZone);

$now = (new DateTime('now'))
->setTimezone($currentTimeZone);
$end = (new DateTime($this->end_datetime ?? 'now'))
->setTimezone(CalendarUtils::getEndTimeZone($this))
->setTimezone($currentTimeZone);

return $now > $end;
}
}
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Calendar",
"description": "Create one-time or recurring events, invite and manage attendees, and keep track of all your events with the Calendar module.",
"keywords": ["calendar"],
"version": "1.5.10",
"version": "1.5.11",
"humhub": {
"minVersion": "1.14"
},
Expand Down

0 comments on commit 9bedce0

Please sign in to comment.