Fix incidents timezones and order

This commit is contained in:
Joseph Cohen 2015-05-07 09:09:03 -05:00
parent 2712e61ea5
commit 5280fc8df4
3 changed files with 26 additions and 7 deletions

View File

@ -76,21 +76,22 @@ class HomeController extends AbstractController
$daysToShow = Setting::get('app_incident_days') ?: 7;
$incidentDays = range(0, $daysToShow - 1);
$dateFormat = Setting::get('date_format') ?: 'jS F Y';
$dateTimeZone = Setting::get('app_timezone');
$allIncidents = Incident::notScheduled()->whereBetween('created_at', [
$startDate->copy()->subDays($daysToShow)->format('Y-m-d').' 00:00:00',
$startDate->format('Y-m-d').' 23:59:59',
])->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) use ($dateFormat) {
return $incident->created_at->format($dateFormat);
])->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) use ($dateTimeZone) {
return (new Date($incident->created_at))
->setTimezone($dateTimeZone)->toDateString();
});
// Add in days that have no incidents
foreach ($incidentDays as $i) {
$date = $startDate->copy()->subDays($i);
$date = (new Date($startDate))->setTimezone($dateTimeZone)->subDays($i);
if (!isset($allIncidents[$date->format($dateFormat)])) {
$allIncidents[$date->format($dateFormat)] = [];
if (!isset($allIncidents[$date->toDateString()])) {
$allIncidents[$date->toDateString()] = [];
}
}

View File

@ -13,6 +13,7 @@ use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Segment\Facades\Segment;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Request;
use Jenssegers\Date\Date;
if (!function_exists('set_active')) {
@ -128,3 +129,20 @@ if (!function_exists('segment_page')) {
}
}
}
if (!function_exists('formatted_date')) {
/**
* Formats a date with the user timezone and the selected format.
*
* @param string $date
*
* @return \Jenssegers\Date\Date
*/
function formatted_date($date)
{
$dateTimeZone = Setting::get('app_timezone');
$dateFormat = Setting::get('date_format') ?: 'jS F Y';
return (new Date($date))->setTimeZone($dateTimeZone)->format($dateFormat);
}
}

View File

@ -1,4 +1,4 @@
<h4>{{ $date }}</h4>
<h4>{{ formatted_date($date) }}</h4>
<div class="timeline">
<div class="content-wrapper">
@forelse($incidents as $incidentID => $incident)