Skip to content

Commit

Permalink
Merge pull request #156 from gheggie/fix-date-calcs-formats
Browse files Browse the repository at this point in the history
Date calc bug fixes and other minor changes
  • Loading branch information
gheggie authored Nov 3, 2020
2 parents a3543a2 + 9326204 commit aee53a1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
49 changes: 28 additions & 21 deletions src/Pages/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,16 @@
use Carbon\Carbon;
use UncleCheese\EventCalendar\Helpers\CalendarUtil;
use UncleCheese\EventCalendar\Pages\Calendar;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\Email\Email;
use SilverStripe\Control\HTTP;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\RSS\RSSFeed;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\CheckboxSetField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\View\Requirements;
use \PageController;
Expand Down Expand Up @@ -83,8 +75,8 @@ public function init()
}
}

public function index(HTTPRequest $r) {

public function index(HTTPRequest $r)
{
$this->extend('index', $r);

switch ($this->DefaultView) {
Expand Down Expand Up @@ -134,22 +126,26 @@ public function week(HTTPRequest $r)
return $this->respond();
}

public function weekend(HTTPRequest $r) {
public function weekend(HTTPRequest $r)
{
$this->setWeekendView();
return $this->respond();
}

public function month(HTTPRequest $r) {
public function month(HTTPRequest $r)
{
$this->setMonthView();
return $this->respond();
}

public function show(HTTPRequest $r) {
public function show(HTTPRequest $r)
{
$this->parseURL($r);
return $this->respond();
}

public function rss() {
public function rss()
{
$this->setDefaultView();
$events = $this->getEvents();
foreach($events as $event) {
Expand Down Expand Up @@ -185,7 +181,8 @@ public function rss() {
/**
* @return string
*/
public function monthjson(HTTPRequest $r) {
public function monthjson(HTTPRequest $r)
{
$json = [];
if (!$r->param('ID')) {
return json_encode($json);
Expand Down Expand Up @@ -551,8 +548,8 @@ public function NextDayLink()
*/
public function PreviousWeekLink()
{
$start = Carbon::parse($this->startDate)->subtractWeek();
$end = Carbon::parse($this->endDate)->subtractWeek();
$start = Carbon::parse($this->startDate)->subWeek();
$end = Carbon::parse($this->endDate)->subWeek();
return $this->getRangeLink($start, $end);
}

Expand All @@ -572,8 +569,7 @@ public function NextWeekLink()
public function NextMonthLink()
{
$start = Carbon::parse($this->startDate)->addMonth();
$end = Carbon::parse($start)->endOfMonth();
return $this->getRangeLink($start, $end);
return $this->getMonthLink($start);
}

/**
Expand All @@ -582,8 +578,19 @@ public function NextMonthLink()
public function PreviousMonthLink()
{
$start = Carbon::parse($this->startDate)->subMonth();
$end = Carbon::parse($start)->endOfMonth();
return $this->getRangeLink($start, $end);
return $this->getMonthLink($start);
}

/**
* @return string
*/
private function getMonthLink($start)
{
return parent::join_links(
$this->Link(),
"show",
$start->format('Ym')
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/CalendarEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class CalendarEvent extends Page

private static $can_be_root = false;

public function getCMSFields() {
public function getCMSFields()
{
$self = $this;

$this->beforeUpdateCMSFields(function($f) use ($self) {
Expand Down

0 comments on commit aee53a1

Please sign in to comment.