Skip to content
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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_DOMAIN=localhost
APP_TIMEZONE=UTC
DISPLAY_TIMEZONE=America/Sao_Paulo

NIGHTWATCH_TOKEN=
LOG_CHANNEL=stack
Expand Down
2 changes: 1 addition & 1 deletion app-modules/bot-discord/src/Events/GreetingsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function handle(Message $message, Discord $discord): void
return;
}

$hour = now()->hour;
$hour = now()->timezone(config('app.display_timezone'))->hour;
$payload = mb_strtolower($message->content);

$response = match (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@
};

// Now indicator
$nowRow = $highlightNow && $isWeek ? (int) now()->format('N') - 1 : -1;
$nowCol = $highlightNow && $isWeek ? (int) now()->format('G') : -1;
$nowRow = $highlightNow && $isWeek ? (int) now(config('app.display_timezone'))->format('N') - 1 : -1;
$nowCol = $highlightNow && $isWeek ? (int) now(config('app.display_timezone'))->format('G') : -1;

// Auto insight
$autoHeadline = $insightHeadline;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
@props([
'startsAt',
'endsAt',
'title',
'icon',
'speakers',
])
@props (['startsAt', 'endsAt', 'title', 'icon', 'speakers'])

@php
/** @var \Carbon\Carbon $startsAt */
/** @var \Carbon\Carbon $endsAt */

$startsAt = $startsAt->timezone(config('app.display_timezone'));
$endsAt = $endsAt->timezone(config('app.display_timezone'));

$config = match (true) {
$endsAt->isPast() => [
'color' => 'text-green-300',
Expand Down Expand Up @@ -51,7 +48,7 @@

@if ($speakers)
<span class="text-text-medium">
// {{ $speakers->map(fn ($speaker) => $speaker->name)->implode(', ') }} \\
// {{ $speakers->map(fn($speaker) => $speaker->name)->implode(', ') }} \\
</span>
@endif
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function handle(

foreach ($messages as $message) {
$timestamp = CarbonImmutable::parse($message['timestamp']);
$oldestTimestamp = $timestamp->format('Y-m-d H:i');
$oldestTimestamp = $timestamp->timezone(config('app.display_timezone'))->format('Y-m-d H:i');

if ($timestamp->isBefore($since)) {
$reachedSince = true;
Expand Down Expand Up @@ -181,7 +181,7 @@ public function handle(
$this->alreadyExistsCount++;
$logger->line(sprintf(
'%s <@%s> %s #%s [EXISTS]',
$timestamp->format('m/d H:i'),
$timestamp->timezone(config('app.display_timezone'))->format('m/d H:i'),
$voiceDto->userDiscordId,
$voiceDto->action,
$channelName,
Expand All @@ -201,7 +201,7 @@ public function handle(

$logger->line(sprintf(
'%s <@%s> %s #%s [NEW]',
$timestamp->format('m/d H:i'),
$timestamp->timezone(config('app.display_timezone'))->format('m/d H:i'),
$voiceDto->userDiscordId,
$voiceDto->action,
$channelName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ class="mb-4 flex items-start gap-2.5 rounded-lg border border-red-300/40 bg-red-
}}
</p>
<p class="mt-0.5 text-xs text-red-600/70 dark:text-red-400/60">
{{ __('panel-admin::moderation.appeal_queue.detail.sla_deadline') }}: {{ $appeal->sla_deadline->format('M d, Y H:i') }}
{{ __('panel-admin::moderation.appeal_queue.detail.sla_deadline') }}: {{
$appeal->sla_deadline
->timezone(config('app.display_timezone'))
->format('M d, Y H:i')
}}
</p>
</div>
</div>
Expand Down Expand Up @@ -381,7 +385,11 @@ class="mb-3 flex items-center gap-2 text-[11px] font-semibold tracking-wider tex
'text-zinc-700 dark:text-zinc-300' => !$isOverdue
])
>
{{ $appeal->sla_deadline?->format('M d, Y H:i') ?? '—' }}
{{
$appeal->sla_deadline
?->timezone(config('app.display_timezone'))
->format('M d, Y H:i') ?? '—'
}}
</div>
@if ($appeal->sla_deadline && !$appeal->status->isResolved())
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ public function __construct(
/** @return Collection<int, array{day: string, msgs: int, users: int}> */
public function get(): Collection
{
$start = Date::now('America/Sao_Paulo')->subDays($this->rangeDays)->startOfDay()->utc();
$tz = config('app.display_timezone');
$start = Date::now($tz)->subDays($this->rangeDays)->startOfDay()->utc();

return DB::table('messages')
->selectRaw("(sent_at AT TIME ZONE 'UTC' AT TIME ZONE 'America/Sao_Paulo')::date AS day")
->selectRaw('(sent_at AT TIME ZONE ?)::date AS day', [$tz])
->selectRaw('COUNT(*) AS total_messages')
->selectRaw('COUNT(DISTINCT external_identity_id) AS unique_users')
->where('sent_at', '>=', $start)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ public function __construct(
/** @return array<int, array{row: int, col: int, value: int}> */
public function get(): array
{
$start = Date::now('America/Sao_Paulo')->subDays($this->rangeDays)->startOfDay()->utc();
$tz = config('app.display_timezone');
$start = Date::now($tz)->subDays($this->rangeDays)->startOfDay()->utc();

return DB::table('messages')
->selectRaw("EXTRACT(DOW FROM sent_at AT TIME ZONE 'UTC' AT TIME ZONE 'America/Sao_Paulo')::int AS dow")
->selectRaw("EXTRACT(HOUR FROM sent_at AT TIME ZONE 'UTC' AT TIME ZONE 'America/Sao_Paulo')::int AS hour")
->selectRaw('EXTRACT(DOW FROM sent_at AT TIME ZONE ?)::int AS dow', [$tz])
->selectRaw('EXTRACT(HOUR FROM sent_at AT TIME ZONE ?)::int AS hour', [$tz])
->selectRaw('COUNT(*) AS total')
->where('sent_at', '>=', $start)
->whereNotNull('sent_at')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private function queryVoiceStats(array $subdivisions): array
private function subdivisions(): array
{
return once(function (): array {
$now = Date::now('America/Sao_Paulo');
$now = Date::now(config('app.display_timezone'));

[$blockCount, $blockSize, $unit] = match (true) {
$this->rangeDays >= 90 => [3, 30, 'days'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public function __construct(
/** @return Collection<int, array{channel_id: string, total_messages: int, unique_users: int}> */
public function get(): Collection
{
$start = Date::now('America/Sao_Paulo')->subDays($this->rangeDays)->startOfDay()->utc();
$tz = config('app.display_timezone');
$start = Date::now($tz)->subDays($this->rangeDays)->startOfDay()->utc();

return DB::table('messages')
->select('channel_id')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ public function __construct(
/** @return array<int, array{row: int, col: int, value: int}> */
public function get(): array
{
$start = Date::now('America/Sao_Paulo')->subDays($this->rangeDays)->startOfDay()->utc();
$tz = config('app.display_timezone');
$start = Date::now($tz)->subDays($this->rangeDays)->startOfDay()->utc();

return DB::table('voice_messages')
->selectRaw("EXTRACT(DOW FROM occurred_at AT TIME ZONE 'America/Sao_Paulo')::int AS dow")
->selectRaw("EXTRACT(HOUR FROM occurred_at AT TIME ZONE 'America/Sao_Paulo')::int AS hour")
->selectRaw('EXTRACT(DOW FROM occurred_at AT TIME ZONE ?)::int AS dow', [$tz])
->selectRaw('EXTRACT(HOUR FROM occurred_at AT TIME ZONE ?)::int AS hour', [$tz])
->selectRaw('COUNT(*) AS total')
->where('occurred_at', '>=', $start)
->whereNotNull('occurred_at')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ public function __construct(
/** @return Collection<int, array{day: string, joins: int, hours: float}> */
public function get(): Collection
{
$start = Date::now('America/Sao_Paulo')->subDays($this->rangeDays)->startOfDay()->utc();
$tz = config('app.display_timezone');
$start = Date::now($tz)->subDays($this->rangeDays)->startOfDay()->utc();

return DB::table('voice_messages')
->selectRaw("(occurred_at AT TIME ZONE 'America/Sao_Paulo')::date AS day")
->selectRaw('(occurred_at AT TIME ZONE ?)::date AS day', [$tz])
->selectRaw('COUNT(*) AS total_joins')
->where('occurred_at', '>=', $start)
->whereNotNull('occurred_at')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public function loadParticipants(): void
return;
}

$start = Date::parse($this->startDate, 'America/Sao_Paulo')->utc();
$end = Date::parse($this->endDate, 'America/Sao_Paulo')->utc();
$tz = config('app.display_timezone');
$start = Date::parse($this->startDate, $tz)->utc();
$end = Date::parse($this->endDate, $tz)->utc();

$messageStats = Message::query()
->where('channel_id', $this->channelId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,14 @@ public function repeatOffenders(): Collection
#[Computed]
public function activityHeatmap(): array
{
$tz = config('app.display_timezone');

$dbData = DB::table('moderation_actions')
->where('created_at', '>=', now()->subDays(30))
->selectRaw('EXTRACT(DOW FROM created_at) as dow, EXTRACT(HOUR FROM created_at) as hour, count(*) as total')
->groupByRaw('EXTRACT(DOW FROM created_at), EXTRACT(HOUR FROM created_at)')
->selectRaw('EXTRACT(DOW FROM created_at AT TIME ZONE ?)::int AS dow', [$tz])
->selectRaw('EXTRACT(HOUR FROM created_at AT TIME ZONE ?)::int AS hour', [$tz])
->selectRaw('COUNT(*) AS total')
->groupBy('dow', 'hour')
->get();

$grid = array_fill(0, 7, array_fill(0, 24, 0));
Expand Down
4 changes: 3 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
|
*/

'timezone' => env('APP_TIMEZONE', 'America/Sao_Paulo'),
'timezone' => env('APP_TIMEZONE', 'UTC'),

'display_timezone' => env('DISPLAY_TIMEZONE', 'America/Sao_Paulo'),

/*
|--------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
public function up(): void
{
DB::statement("ALTER TABLE messages ALTER COLUMN sent_at TYPE timestamptz USING sent_at AT TIME ZONE 'UTC'");
}
};
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ services:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: dev_he4rtbot
TZ: Etc/UTC
PGTZ: Etc/UTC
ports:
- '5432:5432'
volumes:
Expand Down
2 changes: 1 addition & 1 deletion docker/postgres.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

FROM postgres:18-alpine

ENV TZ=America/Sao_Paulo
ENV TZ=Etc/UTC PGTZ=Etc/UTC

RUN set -eux;\
apk update;\
Expand Down
22 changes: 11 additions & 11 deletions resources/views/livewire/connection-hub.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
use He4rt\Identity\ExternalIdentity\Models\ExternalIdentity;
@endphp

@props([
'supportedProviders',
'userProviders',
])
@props (['supportedProviders', 'userProviders'])

@php
/** @var \He4rt\Identity\ExternalIdentity\Enums\IdentityProvider[] $supportedProviders */
Expand All @@ -15,9 +12,10 @@
<div data-slot="card-content" class="space-y-3 px-6">
@foreach ($supportedProviders as $provider)
@php
$connectedProvider = $userProviders->filter(fn (ExternalIdentity $connection) => $connection->provider == $provider->value)->first();
$connectedProvider = $userProviders
->filter(fn(ExternalIdentity $connection) => $connection->provider == $provider->value)
->first();
@endphp

<x-filament::section :secondary="$connectedProvider">
<div class="flex flex-1 items-center gap-3">
<div class="bg-muted mt-0.5 rounded-lg p-2">
Expand All @@ -30,13 +28,15 @@
<x-filament::badge color="green">Connected</x-filament::badge>
@endif
</div>
<p class="text-muted-foreground text-xs leading-relaxed">
{{ $provider->getDescription() }}
</p>
<p class="text-muted-foreground text-xs leading-relaxed">{{ $provider->getDescription() }}</p>
<p class="text-muted-foreground text-xs">
@if ($connectedProvider)
Connected at
<strong>{{ $connectedProvider->updated_at->format('d/m/Y H:i:s') }}</strong>
<strong>{{
$connectedProvider->updated_at
->timezone(config('app.display_timezone'))
->format('d/m/Y H:i:s')
}}</strong>
@else
Nessa autenticação iremos pedir acesso à:
@foreach ($provider->getScopes() as $scope)
Expand All @@ -48,7 +48,7 @@
<x-filament::button
wire:click="{{ !$connectedProvider ? 'connect' : 'disconnect' }}('{{ $provider->value }}')"
:color="$connectedProvider ? 'danger' : 'primary'"
:outlined="(bool)$connectedProvider"
:outlined="(bool) $connectedProvider"
>
{{ $connectedProvider ? 'Disconnect' : 'Connect' }}
</x-filament::button>
Expand Down
3 changes: 2 additions & 1 deletion routes/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
Schedule::command('backup:monitor')
->when(fn () => config('backup.enabled'))
->daily()
->at('09:00');
->at('09:00')
->timezone(config('app.display_timezone'));