Skip to content

Commit

Permalink
v3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmartens committed Feb 21, 2020
1 parent d519a03 commit 6ebd89c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Solspace Calendar Changelog

## 3.0.2 - 2020-02-21
### Added
- Added `dateLocalized` property as a more reliable replacement for `date` when needing to use `|date` filter on `month`/`week`/`day` objects to display translatable date headings or highlight 'today' in calendar views.

### Fixed
- Fixed a bug where `startDateLocalized` and `endDateLocalized` were not working correctly.

## 3.0.1 - 2020-02-20
### Fixed
- Fixed a bug where some timezones would see incorrect behaviour with Month/Week/Day template functions.
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 reliable and powerful event management plugin for Craft.",
"version": "3.0.1",
"version": "3.0.2",
"type": "craft-plugin",
"authors": [
{
Expand Down
31 changes: 23 additions & 8 deletions src/Elements/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,30 @@ public function __construct(array $config = [])
{
parent::__construct($config);

$this->startDateLocalized = new Carbon($this->startDate ?? 'now');
$this->startDate = new Carbon($this->startDate ?? 'now', DateHelper::UTC);
$startDate = $this->startDate;
if ($startDate instanceof \DateTime) {
$startDate = $startDate->format('Y-m-d H:i:s');
}

$endDate = $this->endDate;
if ($endDate instanceof \DateTime) {
$endDate = $endDate->format('Y-m-d H:i:s');
}

$this->startDateLocalized = new Carbon($startDate ?? 'now');
$this->startDate = new Carbon($startDate ?? 'now', DateHelper::UTC);
$this->initialStartDate = $this->startDate->copy();
$this->endDateLocalized = new Carbon($this->endDate);
$this->endDate = new Carbon($this->endDate, DateHelper::UTC);
$this->endDateLocalized = new Carbon($endDate);
$this->endDate = new Carbon($endDate, DateHelper::UTC);
$this->initialEndDate = $this->endDate->copy();
if (null !== $this->until) {
$this->untilLocalized = new Carbon($this->until);
$this->until = new Carbon($this->until, DateHelper::UTC);
$until = $this->until;
if ($until instanceof \DateTime) {
$until = $until->format('Y-m-d H:i:s');
}

$this->untilLocalized = new Carbon($until);
$this->until = new Carbon($until, DateHelper::UTC);
}
}

Expand Down Expand Up @@ -457,8 +472,8 @@ public function cloneForDate(\DateTime $date): Event

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

return $clone;
Expand Down
25 changes: 25 additions & 0 deletions src/Library/Duration/AbstractDuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ abstract class AbstractDuration implements DurationInterface
/** @var Carbon */
protected $startDate;

/** @var Carbon */
protected $startDateLocalized;

/** @var Carbon */
protected $endDate;

/** @var Carbon */
protected $endDateLocalized;

/** @var Event[] */
protected $events;

Expand All @@ -30,6 +36,9 @@ final public function __construct(Carbon $targetDate, array $events = [])
$this->events = $events;
$this->init($targetDate);

$this->startDateLocalized = new Carbon($this->startDate->toDateTimeString());
$this->endDateLocalized = new Carbon($this->endDate->toDateTimeString());

if (null === $this->startDate) {
throw new DurationException('Init method hasn\'t instantiated a startDate');
}
Expand All @@ -54,6 +63,14 @@ final public function getStartDate(): Carbon
return $this->startDate;
}

/**
* @return Carbon
*/
final public function getStartDateLocalized(): Carbon
{
return $this->startDateLocalized;
}

/**
* @return Carbon
*/
Expand All @@ -62,6 +79,14 @@ final public function getEndDate(): Carbon
return $this->endDate;
}

/**
* @return Carbon
*/
final public function getEndDateLocalized(): Carbon
{
return $this->endDateLocalized;
}

/**
* @return Event[]
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Library/Events/AbstractEventCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ final public function getDate(): Carbon
return $this->duration->getStartDate()->copy();
}

/**
* Returns the localized start date of the event collection
*
* @return Carbon
*/
final public function getDateLocalized(): Carbon
{
return $this->duration->getStartDateLocalized()->copy();
}

/**
* @return Carbon
*/
Expand Down
2 changes: 1 addition & 1 deletion src/codepack/templates/month.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h3>
<tr>
{% for day in week %}
{% if month.containsDate(day.date) %}
<td class="day_cell{{ day.date.isToday ? " today" }}">
<td class="day_cell{{ day.dateLocalized.isToday ? " today" }}">
<div class="date{{ day.eventCount ? " has_events" }}">
<a class="num"
href="{{ siteUrl }}demo/day/{{ segment3 == 'calendar' ? "calendar/"~segment4~"/" }}{{ day.date.format('Y/m/d') }}">
Expand Down
4 changes: 2 additions & 2 deletions src/codepack/templates/week.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ <h3>

{% for day in week %}
<ul class="list-group mb-4">
<li class="list-group-item list-group-item-{{ day.date.isToday ? "warning" : "secondary" }}">
<li class="list-group-item list-group-item-{{ day.dateLocalized.isToday ? "warning" : "secondary" }}">
<a class="text-dark font-weight-bold"
href="{{ siteUrl }}demo/day/{{ segment3 == "calendar" ? segment3~"/"~segment4~"/" }}{{ day.date.format('Y/m/d') }}">
{% if day.date.isToday %}
{% if day.dateLocalized.isToday %}
TODAY
{% else %}
{{ day.date.format('l, F j, Y') }}
Expand Down

0 comments on commit 6ebd89c

Please sign in to comment.