Skip to content

Commit 382a301

Browse files
authored
[1.x] Format dates to browsers timezone (#417)
* Cache card * Exceptions card * Queues card * Servers card * Slow jobs card * Slow outgoing requests card * Slow queries card * Slow requests card * Usage card
1 parent 5dd3cd2 commit 382a301

12 files changed

+38
-14
lines changed

dist/pulse.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/pulse.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
11
import Chart from 'chart.js/auto';
22

3+
const formatDate = (value) => {
4+
if (value.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/) === null) {
5+
throw new Error(`Unknown date format [${value}].`);
6+
}
7+
8+
const [date, time] = value.split(' ')
9+
const [year, month, day] = date.split('-').map(Number)
10+
const [hour, minute, second] = time.split(':').map(Number)
11+
12+
return new Date(
13+
Date.UTC(year, month - 1, day, hour, minute, second, 0)
14+
).toLocaleString(undefined, {
15+
year: "2-digit",
16+
day: "2-digit",
17+
month: "2-digit",
18+
hourCycle: "h24",
19+
hour: "2-digit",
20+
minute: "2-digit",
21+
second: "2-digit",
22+
timeZoneName: "short"
23+
});
24+
}
25+
326
window.Chart = Chart;
27+
window.formatDate = formatDate

resources/views/components/card-header.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</div>
99
@endif
1010
<hgroup class="flex flex-wrap items-baseline gap-x-2 overflow-hidden">
11-
<h2 class="text-base font-bold text-gray-600 dark:text-gray-300 truncate" title="{{ $title }}">{{ $name }}</h2>
11+
<h2 class="text-base font-bold text-gray-600 dark:text-gray-300 truncate" @if($attributes->has('x-bind:title')) x-bind:title="{{ $attributes->get('x-bind:title') }}" @else title="{{ $title }}" @endif>{{ $name }}</h2>
1212
@if ($details)
1313
<p class="text-gray-400 dark:text-gray-600 font-medium truncate"><small class="text-xs">{{ $details }}</small></p>
1414
@endif

resources/views/livewire/cache.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<x-pulse::card :cols="$cols" :rows="$rows" :class="$class">
33
<x-pulse::card-header
44
name="Cache"
5-
title="Global Time: {{ number_format($allTime) }}ms; Global run at: {{ $allRunAt }}; Key Time: {{ number_format($keyTime) }}ms; Key run at: {{ $keyRunAt }};"
5+
x-bind:title="`Global Time: {{ number_format($allTime) }}ms; Global run at: ${formatDate('{{ $allRunAt }}')}; Key Time: {{ number_format($keyTime) }}ms; Key run at: ${formatDate('{{ $keyRunAt }}')};`"
66
details="past {{ $this->periodForHumans() }}"
77
>
88
<x-slot:icon>

resources/views/livewire/exceptions.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<x-pulse::card :cols="$cols" :rows="$rows" :class="$class">
22
<x-pulse::card-header
33
name="Exceptions"
4-
title="Time: {{ number_format($time) }}ms; Run at: {{ $runAt }};"
4+
x-bind:title="`Time: {{ number_format($time) }}ms; Run at: ${formatDate('{{ $runAt }}')};`"
55
details="past {{ $this->periodForHumans() }}"
66
>
77
<x-slot:icon>

resources/views/livewire/queues.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<x-pulse::card :cols="$cols" :rows="$rows" :class="$class">
33
<x-pulse::card-header
44
name="Queues"
5-
title="Time: {{ number_format($time) }}ms; Run at: {{ $runAt }};"
5+
x-bind:title="`Time: {{ number_format($time) }}ms; Run at: ${formatDate('{{ $runAt }}')};`"
66
details="past {{ $this->periodForHumans() }}"
77
>
88
<x-slot:icon>
@@ -196,7 +196,7 @@ class="h-14"
196196
})
197197
},
198198
labels(readings) {
199-
return Object.keys(readings.queued)
199+
return Object.keys(readings.queued).map(formatDate)
200200
},
201201
scale(data) {
202202
return Object.values(data).map(value => value * (1 / config.sampleRate ))

resources/views/livewire/servers.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class="overflow-x-auto pb-px default:col-span-full default:lg:col-span-{{ $cols
4949
</div>
5050
<div wire:key="{{ $slug }}-name" class="flex items-center pr-8 xl:pr-12 {{ $servers->count() > 1 ? 'py-2' : '' }} {{ ! $server->recently_reported ? 'opacity-25 animate-pulse' : '' }}">
5151
<x-pulse::icons.server class="w-6 h-6 mr-2 stroke-gray-500 dark:stroke-gray-400" />
52-
<span class="text-base font-bold text-gray-600 dark:text-gray-300" title="Time: {{ number_format($time) }}ms; Run at: {{ $runAt }};">{{ $server->name }}</span>
52+
<span class="text-base font-bold text-gray-600 dark:text-gray-300" x-bind:title="`Time: {{ number_format($time) }}ms; Run at: ${formatDate('{{ $runAt }}')};`">{{ $server->name }}</span>
5353
</div>
5454
<div wire:key="{{ $slug }}-cpu" class="flex items-center {{ $servers->count() > 1 ? 'py-2' : '' }} {{ ! $server->recently_reported ? 'opacity-25 animate-pulse' : '' }}">
5555
<div class="text-xl font-bold text-gray-700 dark:text-gray-200 w-14 whitespace-nowrap tabular-nums">
@@ -129,7 +129,7 @@ class="w-full min-w-[5rem] max-w-xs h-9 relative"
129129
{
130130
type: 'line',
131131
data: {
132-
labels: config.labels,
132+
labels: config.labels.map(formatDate),
133133
datasets: [
134134
{
135135
label: 'CPU Percent',
@@ -209,7 +209,7 @@ class="w-full min-w-[5rem] max-w-xs h-9 relative"
209209
{
210210
type: 'line',
211211
data: {
212-
labels: config.labels,
212+
labels: config.labels.map(formatDate),
213213
datasets: [
214214
{
215215
label: 'Memory Used',

resources/views/livewire/slow-jobs.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<x-pulse::card :cols="$cols" :rows="$rows" :class="$class">
22
<x-pulse::card-header
33
name="Slow Jobs"
4-
title="Time: {{ number_format($time, 0) }}ms; Run at: {{ $runAt }};"
4+
x-bind:title="`Time: {{ number_format($time, 0) }}ms; Run at: ${formatDate('{{ $runAt }}')};`"
55
details="{{ is_array($config['threshold']) ? '' : $config['threshold'].'ms threshold, ' }}past {{ $this->periodForHumans() }}"
66
>
77
<x-slot:icon>

resources/views/livewire/slow-outgoing-requests.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<x-pulse::card :cols="$cols" :rows="$rows" :class="$class">
33
<x-pulse::card-header
44
name="Slow Outgoing Requests"
5-
title="Time: {{ number_format($time) }}ms; Run at: {{ $runAt }};"
5+
title="`Time: {{ number_format($time) }}ms; Run at: ${formatDate('{{ $runAt }}')};`"
66
details="{{ is_array($config['threshold']) ? '' : $config['threshold'].'ms threshold, ' }}past {{ $this->periodForHumans() }}"
77
>
88
<x-slot:icon>

resources/views/livewire/slow-queries.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<x-pulse::card :cols="$cols" :rows="$rows" :class="$class">
2020
<x-pulse::card-header
2121
name="Slow Queries"
22-
title="Time: {{ number_format($time) }}ms; Run at: {{ $runAt }};"
22+
x-bind:title="`Time: {{ number_format($time) }}ms; Run at: ${formatDate('{{ $runAt }}')};`"
2323
details="{{ is_array($config['threshold']) ? '' : $config['threshold'].'ms threshold, ' }}past {{ $this->periodForHumans() }}"
2424
>
2525
<x-slot:icon>

resources/views/livewire/slow-requests.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<x-pulse::card :cols="$cols" :rows="$rows" :class="$class">
22
<x-pulse::card-header
33
name="Slow Requests"
4-
title="Time: {{ number_format($time) }}ms; Run at: {{ $runAt }};"
4+
x-bind:title="`Time: {{ number_format($time) }}ms; Run at: ${formatDate('{{ $runAt }}')};`"
55
details="{{ is_array($config['threshold']) ? '' : $config['threshold'].'ms threshold, ' }}past {{ $this->periodForHumans() }}"
66
>
77
<x-slot:icon>

resources/views/livewire/usage.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'jobs' => 'Top 10 Users Dispatching Jobs',
77
default => 'Application Usage'
88
}"
9-
title="Time: {{ number_format($time) }}ms; Run at: {{ $runAt }};"
9+
x-bind:title="`Time: {{ number_format($time) }}ms; Run at: ${formatDate('{{ $runAt }}')};`"
1010
details="{{ $this->usage === 'slow_requests' ? (is_array($slowRequestsConfig['threshold']) ? '' : $slowRequestsConfig['threshold'].'ms threshold, ') : '' }}past {{ $this->periodForHumans() }}"
1111
>
1212
<x-slot:icon>

0 commit comments

Comments
 (0)