diff --git a/src/Fields/Date.php b/src/Fields/Date.php index 5f87eadf..ced795d9 100644 --- a/src/Fields/Date.php +++ b/src/Fields/Date.php @@ -3,6 +3,7 @@ namespace Cone\Root\Fields; use Closure; +use Cone\Root\Root; use DateTimeInterface; use DateTimeZone; use Illuminate\Database\Eloquent\Model; @@ -27,11 +28,6 @@ class Date extends Field */ protected bool $withTime = false; - /** - * The default timezone. - */ - protected static ?string $defaultTimezone = null; - /** * Create a new field instance. */ @@ -41,15 +37,7 @@ public function __construct(string $label, Closure|string|null $modelAttribute = $this->type('date'); $this->step(1); - $this->timezone(static::$defaultTimezone ?: Config::get('app.timezone')); - } - - /** - * Set the default timezone. - */ - public static function defaultTimezone(string|DateTimeZone $value): void - { - static::$defaultTimezone = $value instanceof DateTimeZone ? $value->getName() : $value; + $this->timezone(Root::instance()->getTimezone()); } /** diff --git a/src/Models/Notification.php b/src/Models/Notification.php index 6e445194..0701f2fd 100644 --- a/src/Models/Notification.php +++ b/src/Models/Notification.php @@ -4,6 +4,7 @@ use Cone\Root\Database\Factories\NotificationFactory; use Cone\Root\Interfaces\Models\Notification as Contract; +use Cone\Root\Root; use Cone\Root\Traits\InteractsWithProxy; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Concerns\HasUuids; @@ -68,7 +69,7 @@ protected function formattedCreatedAt(): Attribute { return new Attribute( get: function (): ?string { - return $this->created_at?->isoFormat('YYYY. MMMM DD. HH:mm'); + return $this->created_at?->setTimezone(Root::instance()->getTimezone())?->isoFormat('YYYY. MMMM DD. HH:mm'); } ); } diff --git a/src/Root.php b/src/Root.php index 734c247c..1512bb68 100644 --- a/src/Root.php +++ b/src/Root.php @@ -8,6 +8,7 @@ use Cone\Root\Navigation\Registry as Navigation; use Cone\Root\Resources\Resources; use Cone\Root\Widgets\Widgets; +use DateTimeZone; use Illuminate\Contracts\Foundation\Application; use Illuminate\Http\Request; use Illuminate\Support\Facades\App; @@ -59,6 +60,8 @@ class Root */ protected ?Closure $authResolver = null; + protected string $timezone; + /** * Create a new Root instance. */ @@ -69,6 +72,7 @@ public function __construct(Application $app) $this->widgets = new Widgets(); $this->navigation = new Navigation(); $this->breadcrumbs = new Breadcrumbs(); + $this->timezone = $app['config']->get('app.timezone'); } /** @@ -171,4 +175,20 @@ public function authorize(Closure $callback): void { $this->authResolver = $callback; } + + /** + * Set the Root timezone. + */ + public function setTimezone(string|DateTimeZone $value): void + { + $this->timezone = $value instanceof DateTimeZone ? $value->getName() : $value; + } + + /** + * Get the Root timezone. + */ + public function getTimezone(): string + { + return $this->timezone; + } }