wdelfuego / nova-datetime Goto Github PK
View Code? Open in Web Editor NEWMakes working with DateTime fields in Laravel's Nova easier
Makes working with DateTime fields in Laravel's Nova easier
I just updated my nova installation to the latest version as described in the title and the datetime fields unfortunately no longer display anything.
As mentioned here they messed up the displayUsing function.
You probably don't have to do anything because it's their problem but I'll keep you posted if it's fixed or not in the next version.
Hi! I configured timezone in config/app.php
, for example:
'timezone' => 'Europe/Moscow',
Then I added this DateTime
field and Nova default DateTime
field:
\Wdelfuego\Nova\DateTime\Fields\DateTime::make(__('Date 1'), 'date'),
\Laravel\Nova\Fields\DateTime::make(__('Date 2'), 'date'),
and I saw:
Nova default DateTime
field show time with applying timezone.
This DateTime
field show time without applying timezone.
Nova 4 defers formatting of Date/DateTime values in pickers to the browser by using its default picker implementation.
Many users have requested ways to customize the picker in different ways.
A custom DateTime field that implements its own customizable DateTime picker would be a super valuable addition to this package.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.