corcel / acf

Advanced Custom Fields (ACF) plugin for Corcel
126 stars 98 forks source link

DateTime fields are returning current date when field is empty #77

Open joris-ati4 opened 5 years ago

joris-ati4 commented 5 years ago

Hi,

First off all I would like to thank you for this cool package and the work you invested. While working with this package I noticed a problem that is affecting the DateTime fields.

When doing a call on a ACF DateTime field that is empty, the method returns a Carbon Object containing the current date. I think it would be better if the method returns false when the value for the requested field is empty.

The reason that the datePicker() method returns the current date and not false is because the methods assigns a value to the date with the following code:

$this->date = Carbon::createFromFormat($format, $dateString);

In the case the field is empty, $dateString will be empty and $this->date will have the current date.

What do you think about this fix ? I will submit a PR and link in within this issue

Thank you,

kasunintervest commented 4 years ago

I'm still facing this issue.

Quick fix: vendor/corcel/acf/src/Field/DateTime.php Line 28

$this->date = $dateString ? Carbon::createFromFormat($format, $dateString) : null;

wheeleran commented 1 year ago

has there been a fix for this? a function or snippet that returns null on empty date string?