Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localize group calendar event times #1361

Merged
merged 3 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion core/plugins/groups/calendar/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
// No direct access
defined('_HZEXEC_') or die();

$pluginDirectory = __DIR__;

require_once "$pluginDirectory/helpers/userLocalizer.php";

/**
* Groups Plugin class for calendar
*/
Expand Down Expand Up @@ -407,6 +411,7 @@ public function events()
$start = Date::of($start . ' 00:00:00');
$end = Date::of($end . ' 00:00:00');
$end->modify('-1 second');
$userLocalizer = new UserLocalizer();

// get calendar events
$eventsCalendar = \Components\Events\Models\Calendar::getInstance();
Expand Down Expand Up @@ -434,6 +439,8 @@ public function events()
// merge events with repeating events
$rawEvents = $rawEvents->merge($rawEventsRepeating);

$timezone = $userLocalizer->getTimezone();

// loop through each event to return it
foreach ($rawEvents as $rawEvent)
{
Expand All @@ -449,7 +456,7 @@ public function events()
$event->title = $rawEvent->get('title');
$event->allDay = $rawEvent->get('allday') == 1;
$event->url = $rawEvent->link();
$event->start = ($event->allDay == 1) ? $up->setTimezone('UTC')->format($timeFormat, true) : $up->toLocal($timeFormat, $ignoreDst);
$event->start = ($event->allDay == 1) ? $up->setTimezone('UTC')->format($timeFormat, true) : $up->toTimezone($timezone, $timeFormat, $ignoreDst);
$event->className = ($rawEvent->get('calendar_id')) ? 'calendar-' . $rawEvent->get('calendar_id') : 'calendar-0';
if ($rawEvent->get('publish_down') && $rawEvent->get('publish_down') != '0000-00-00 00:00:00')
{
Expand Down
43 changes: 43 additions & 0 deletions core/plugins/groups/calendar/helpers/userLocalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* @package hubzero-cms
* @copyright Copyright 2005-2019 HUBzero Foundation, LLC.
* @license http://opensource.org/licenses/MIT MIT
*/

// No direct access
defined('_HZEXEC_') or die();

use Hubzero\Utility\Arr;

class UserLocalizer
{

public function __construct()
{
$this->db = App::get('db');
$this->systemTimezone = Config::get('offset');
}

public function getTimezone()
{
if (!User::isGuest())
{
$timezone = $this->_getUserTimezone();
}
else
{
$timezone = $this->systemTimezone;
}

return $timezone;
}

protected function _getUserTimezone()
{
$userParams = json_decode(User::get('params'), 1);

return Arr::getValue($userParams, 'timezone', $this->systemTimezone);
}

}
19 changes: 15 additions & 4 deletions core/plugins/groups/calendar/views/calendar/tmpl/display.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

// No direct access
defined('_HZEXEC_') or die();

$userLocalizer = new UserLocalizer();
$timezone = $userLocalizer->getTimezone();
?>

<?php if ($this->getError()) { ?>
Expand Down Expand Up @@ -67,16 +70,24 @@
</dd>
<?php if ($event->get('publish_down') && $event->get('publish_down') != '0000-00-00 00:00:00') : ?>
<dd class="start-and-end">
<?php echo Date::of($event->get('publish_up'))->toLocal('l, F d, Y @ g:i a', $ignoreDst); ?>
<?php
echo Date::of($event->get('publish_up'))->toTimezone($timezone, 'l, F d, Y @ g:i a', $ignoreDst);
?>
&mdash;
<?php echo Date::of($event->get('publish_down'))->toLocal('l, F d, Y @ g:i a', $ignoreDst); ?>
<?php
echo Date::of($event->get('publish_down'))->toTimezone($timezone, 'l, F d, Y @ g:i a', $ignoreDst);
?>
</dd>
<?php else : ?>
<dd class="date">
<?php echo Date::of($event->get('publish_up'))->toLocal('l, F d, Y', $ignoreDst); ?>
<?php
echo Date::of($event->get('publish_up'))->toTimezone($timezone, 'l, F d, Y @ g:i a', $ignoreDst);
?>
<dd>
<dd class="time">
<?php echo Date::of($event->get('publish_up'))->toLocal(Lang::txt('TIME_FORMAT_HZ1'), $ignoreDst); ?>
<?php
echo Date::of($event->get('publish_up'))->toTimezone($timezone, 'l, F d, Y @ g:i a', $ignoreDst);
?>
<dd>
<?php endif; ?>
</dl>
Expand Down