Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Mar 29, 2024
1 parent 6e8aba3 commit 945f667
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
16 changes: 2 additions & 14 deletions src/Fields/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Cone\Root\Fields;

use Closure;
use Cone\Root\Root;
use DateTimeInterface;
use DateTimeZone;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -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.
*/
Expand All @@ -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());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Models/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
);
}
Expand Down
20 changes: 20 additions & 0 deletions src/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,6 +60,8 @@ class Root
*/
protected ?Closure $authResolver = null;

protected string $timezone;

/**
* Create a new Root instance.
*/
Expand All @@ -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');
}

/**
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 945f667

Please sign in to comment.