Skip to content

Commit 0642d3f

Browse files
committed
Improve incident timestamps
1 parent f54eb5a commit 0642d3f

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

resources/views/components/incident.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<h3 class="text-base md:text-xl break-words font-semibold">
1515
<a href="{{ route('cachet.status-page.incident', $incident) }}">{{ $incident->name}}</a>
1616
</h3>
17-
<span class="text-xs text-zinc-500">{{ $incident->occurred_at->diffForHumans() }}{{ $incident->occurred_at->toDayDateTimeString() }}</span>
17+
<span class="text-xs text-zinc-500">{{ $incident->timestamp->diffForHumans() }}{{ $incident->timestamp->toDayDateTimeString() }}</span>
1818
</div>
1919
<div>
2020
<x-cachet::incident-badge :type="$incident->status" />

resources/views/status-page/incident.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<div class="flex flex-col gap-6">
1010
<div class="flex flex-col gap-14 w-full">
11-
<x-cachet::incident :date="$incident->occurred_at" :incidents="[$incident]" />
11+
<x-cachet::incident :date="$incident->timestamp" :incidents="[$incident]" />
1212
</div>
1313
</div>
1414
</div>

src/Models/Incident.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Cachet\Events\Incidents\IncidentDeleted;
99
use Cachet\Events\Incidents\IncidentUpdated;
1010
use Illuminate\Database\Eloquent\Builder;
11+
use Illuminate\Database\Eloquent\Casts\Attribute;
1112
use Illuminate\Database\Eloquent\Factories\HasFactory;
1213
use Illuminate\Database\Eloquent\Model;
1314
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -103,6 +104,11 @@ public function scopeStickied(Builder $query): Builder
103104
return $query->where('stickied', true);
104105
}
105106

107+
public function timestamp(): Attribute
108+
{
109+
return Attribute::get(fn () => $this->occurred_at ?: $this->created_at);
110+
}
111+
106112
/**
107113
* Render the Markdown message.
108114
*/

src/View/Components/Incidents.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Cachet\Models\Incident;
66
use Cachet\Settings\AppSettings;
77
use Illuminate\Contracts\View\View;
8+
use Illuminate\Database\Eloquent\Builder;
89
use Illuminate\Support\Carbon;
910
use Illuminate\Support\Collection;
1011
use Illuminate\View\Component;
@@ -44,13 +45,21 @@ private function incidents(Carbon $startDate, Carbon $endDate, bool $onlyDisrupt
4445
'incidentUpdates' => fn ($query) => $query->orderByDesc('created_at'),
4546
])
4647
->where('visible', '>=', ! auth()->check())
47-
->whereBetween('occurred_at', [
48-
$endDate->startOfDay()->toDateTimeString(),
49-
$startDate->endofDay()->toDateTimeString(),
50-
])
48+
->where(function (Builder $query) use ($endDate, $startDate) {
49+
$query->whereBetween('occurred_at', [
50+
$endDate->startOfDay()->toDateTimeString(),
51+
$startDate->endofDay()->toDateTimeString(),
52+
])->orWhere(function (Builder $query) use ($endDate, $startDate) {
53+
$query->whereNull('occurred_at')->whereBetween('created_at', [
54+
$endDate->startOfDay()->toDateTimeString(),
55+
$startDate->endofDay()->toDateTimeString(),
56+
]);
57+
});
58+
})
5159
->orderBy('occurred_at', 'desc')
60+
->orderBy('created_at', 'desc')
5261
->get()
53-
->groupBy(fn (Incident $incident) => $incident->occurred_at?->toDateString())
62+
->groupBy(fn (Incident $incident) => $incident->timestamp->toDateString())
5463
->union(
5564
// Back-fill any missing dates...
5665
collect($endDate->toPeriod($startDate))

0 commit comments

Comments
 (0)