Skip to content

Commit

Permalink
v2.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmartens committed Nov 1, 2018
1 parent 0c6f5da commit 1c02e3d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Solspace Calendar Changelog

## 2.0.9 - 2018-11-01
### Changed
- Updated demo templates approach for viewing individual recurrences to validate that the date segments in URL match against an available recurrence.

### Fixed
- Fixed a bug where `startDateLocalized|date()` was not displaying the correct date when viewing recurrences.
- Fixed a bug where the `occurrenceDate` parameter was not working (was originally named `targetDate` - aliased now).

## 2.0.8 - 2018-10-17
### Fixed
- Fixed a bug where the CP Events list page would not load because of an accidental reference to Freeform.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "solspace/craft3-calendar",
"description": "The most powerful event management plugin for Craft.",
"version": "2.0.8",
"version": "2.0.9",
"type": "craft-plugin",
"minimum-stability": "dev",
"authors": [
Expand Down
45 changes: 41 additions & 4 deletions src/Elements/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
use Solspace\Calendar\Library\Configurations\Occurrences;
use Solspace\Calendar\Library\DateHelper;
use Solspace\Calendar\Library\Duration\EventDuration;
use Solspace\Calendar\Library\Exceptions\CalendarException;
use Solspace\Calendar\Library\RecurrenceHelper;
use Solspace\Calendar\Models\CalendarModel;
use Solspace\Calendar\Models\ExceptionModel;
use Solspace\Calendar\Models\SelectDateModel;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use yii\base\Model;

class Event extends Element implements \JsonSerializable
{
Expand Down Expand Up @@ -413,6 +413,10 @@ public function cloneForDate(\DateTime $date): Event
}

if (null !== $date) {
if (!$this->happensOn($date)) {
throw new CalendarException('Invalid event date');
}

$startDate = $this->getStartDate()->copy();
$endDate = $this->getEndDate()->copy();

Expand All @@ -429,8 +433,10 @@ public function cloneForDate(\DateTime $date): Event
$endDate = $startDate->copy();
$endDate->addSeconds($diffInSeconds);

$clone->startDate = $startDate;
$clone->endDate = $endDate;
$clone->startDate = $startDate;
$clone->endDate = $endDate;
$clone->startDateLocalized = new Carbon($startDate);
$clone->endDateLocalized = new Carbon($endDate);
}

return $clone;
Expand Down Expand Up @@ -755,6 +761,37 @@ public function getOccurrenceDatesBetween(\DateTime $rangeStart = null, \DateTim
return $occurrences;
}

/**
* @param \DateTime $date
*
* @return bool
* @throws \Exception
*/
public function happensOn(\DateTime $date): bool
{
if (!$date instanceof Carbon) {
$date = new Carbon($date->format('Y-m-d'), DateHelper::UTC);
}
$date->setTime(0, 0, 0);

if ($date->toDateString() === $this->getStartDate()->toDateString()) {
return true;
}

if ($this->repeatsOnSelectDates()) {
$dates = $this->getSelectDatesAsString();

return \in_array($date->toDateString(), $dates, true);
}

$rrule = $this->getRRuleObject();
if (null === $rrule) {
return false;
}

return $rrule->occursAt($date);
}

/**
* @return Carbon|null
*/
Expand Down Expand Up @@ -1391,7 +1428,7 @@ private function getRRuleObject()
[
'FREQ' => $this->getFrequency(),
'INTERVAL' => $this->interval,
'DTSTART' => $this->initialStartDate,
'DTSTART' => $this->initialStartDate->copy()->setTime(0, 0, 0),
'UNTIL' => $this->getUntil(),
'COUNT' => $this->count,
'BYDAY' => $this->byDay,
Expand Down
2 changes: 2 additions & 0 deletions src/Variables/CalendarVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public function event($id, array $options = [])
$targetDate = null;
if (isset($options['targetDate'])) {
$targetDate = new Carbon($options['targetDate'], DateHelper::UTC);
} else if (isset($options['occurrenceDate'])) {
$targetDate = new Carbon($options['occurrenceDate'], DateHelper::UTC);
}

$siteId = null;
Expand Down
4 changes: 2 additions & 2 deletions src/codepack/templates/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ <h3>{{ event.title }}</h3>
<ul class="list-group">
{% for occurrence in occurrences %}
<li class="list-group-item" style="border-left: 5px solid {{ occurrence.calendar.color }};">
<a href="{{ siteUrl }}calendar_demo/event/{{ occurrence.id }}/{{ occurrence.startDate.format("Y/m/d") }}"
<a href="{{ siteUrl }}demo/event/{{ occurrence.id }}/{{ occurrence.startDate.format("Y/m/d") }}"
class="badge"
style="background-color: {{ occurrence.calendar.color }}; color: {{ occurrence.calendar.contrastColor }} !important;">
View Recurrence
</a>
<a href="{{ siteUrl }}calendar_demo/day/{{ occurrence.startDate.format("Y/m/d") }}" class="badge">
<a href="{{ siteUrl }}demo/day/{{ occurrence.startDate.format("Y/m/d") }}" class="badge">
View Day in Calendar
</a>
<span class="glyphicon glyphicon-time"></span>&nbsp;
Expand Down

0 comments on commit 1c02e3d

Please sign in to comment.