laravel / nova-issues

554 stars 34 forks source link

Datetime Format #4042

Closed gepopp closed 2 years ago

gepopp commented 2 years ago

Description:

Since the Format function on DateTime was removed, how can i now define how its displayed in the resource inde?

wdelfuego commented 2 years ago

We’ve been discussing this in issue 3929: https://github.com/laravel/nova-issues/discussions/3929

I’ve created a small package that brings back support for custom datetime formats: https://github.com/wdelfuego/nova4-formattable-date

Elshaden commented 2 years ago

@wdelfuego Thanks for the package, it works, but it does not change how the Picker shows the date format. it only woks in index and detail page. not create and update.

Is there a simple way to change the Picker format ?

wdelfuego commented 2 years ago

@Elshaden Nova now supports datetime formatting natively so that package is no longer necessary. I’ve put the code in a new package called nova-datetime that offers some helper functions around novas datetime fields but if it’s just for formatting you can do so natively now.

As to editing the picker formats; Nova leaves that to the browser and there are no features I am aware of that would allow you to customize it, except by building your own custom datetime picker field.

Elshaden commented 2 years ago

Hi @wdelfuego I am trying to do what you said using native Nova function, but could not find anywhere in Documentation how this is done.

can you please share an example.

wdelfuego commented 2 years ago

https://github.com/laravel/nova-issues/discussions/3929#discussioncomment-2607539

See this comment by nova’s main developer

Elshaden commented 2 years ago

@wdelfuego I tried it and no It did not work, maybe I missing something.

 DateTime::make('Created At')->displayUsing(fn ($value) => $value->diffForHumans()),

image

wdelfuego commented 2 years ago

There are currently more users reporting problems with Nova's DateTime fields, not originating from this package, but from Nova itself. Seems a breaking bug wrt value customisation was introduced in v4.12.14. Thanks @Sotiris-k for the heads-up.

See https://github.com/laravel/nova-issues/issues/4665 for more info. The bug was already closed, @crynobone confirmed the fix is pending release so update as soon as the new version is released and let me know if your issue persists!

Jon78 commented 2 years ago

@wdelfuego the issue persists in 4.13.0

wdelfuego commented 2 years ago

Hi @Jon78, first of all, a million thanks to you for all the books I didn't have to read in secondary school thanks to your website 😄.

If there's an issue with my nova-datetime package we'll create a thread there to discuss it as this is a general nova-issues thread I have nothing to do with, I just supplied a temporal package for some missing functionality in Nova that was added natively in 4.2.4 already. What issue are you referring to specifically?

Jon78 commented 2 years ago

Sorry, I was referring to the issue in Nova! Will check out your package right now

crynobone commented 2 years ago

@Jon78 the issue has been foxed on 4.13.0, if you still jave an issue submit a new issue but first do try updatong the assets, most forgot this step.

wdelfuego commented 2 years ago

Still curious what issue you are referring to though; if it's date picker formatting; Nova defers that responsibility to the browser since version 4 so you'd have to make or use custom fields for that.

Jon78 commented 2 years ago

@Jon78 the issue has been foxed on 4.13.0, if you still jave an issue submit a new issue but first do try updatong the assets, most forgot this step.

Right, missed that one. Thanks!

Jon78 commented 2 years ago

Still curious what issue you are referring to though; if it's date picker formatting; Nova defers that responsibility to the browser since version 4 so you'd have to make or use custom fields for that.

In Nova 3 we used https://github.com/techouse/intl-date-time for formatting and customizing the DateTime-field. For example, sometimes you want a 'now' button to select not just the current date but also the current time. If you know of an easy way to do that..

wdelfuego commented 2 years ago

If you know of an easy way to do that..

Using native Nova fields I don't think there is one, since these use the HTML5 pickers supplied by the browser.

I think a custom field is the way to go; we could build a custom datetime field (with custom picker) together and add it to the nova-datetime package. I've created a thread to discuss it if anyone's interested in that feature.