Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeZone Problem. #6

Open
Tanariel opened this issue Oct 22, 2023 · 1 comment
Open

TimeZone Problem. #6

Tanariel opened this issue Oct 22, 2023 · 1 comment

Comments

@Tanariel
Copy link

Tanariel commented Oct 22, 2023

Related to issue #1

Unfortunately the implemented solution doesn't follow the nova behavior with timezones.

the solution you implemented

public static function withDateFormatFunction() : callable { return function (string $format) { return $this->displayUsing(fn ($d) => ($d instanceof Carbon) ? (config('app.timezone') ? $d->setTimezone(new DateTimeZone(config('app.timezone')))->translatedFormat($format) : $d->translatedFormat($format)) : (($d instanceof DateTimeInterface) ? (config('app.timezone') ? $d->setTimezone(new DateTimeZone(config('app.timezone')))->format($format) : $d->format($format)) : '') ); }; }

is using config('app.timezone') which is the default timezone of the application. But laravel nova is providing a way to personalise the timezone per user : see => https://nova.laravel.com/docs/4.0/resources/date-fields.html#timezones

use Laravel\Nova\Nova;
use Illuminate\Http\Request;

/**

Bootstrap any application services.

@return void
*/
public function boot()
{
parent::boot();

Nova::userTimezone(function (Request $request) {
return $request->user()?->timezone;
});
}

to be compatible with nova and the default customisation of timezone foreach user, the code should somehow look like this instead :

$d->setTimezone(new DateTimeZone($request->user()->timezone ?? config('app.timezone')))->translatedFormat($format)

if you see what i mean ?
Actually i'm facing the problem where the app default TZ is UTC, but users are coming from multiple tz and will only see the fields in the app default tz if i use this bundle.

@wdelfuego
Copy link
Owner

Hey, thanks for reporting and the explanation!

I'll look into this when I can, in the meantime PRs are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants