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

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

Open
joris-ati4 opened this issue Apr 25, 2019 · 2 comments
Open

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

joris-ati4 opened this issue Apr 25, 2019 · 2 comments

Comments

@joris-ati4
Copy link

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
Copy link

kasunintervest commented Aug 12, 2020

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
Copy link

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

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

3 participants