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

Update Date.php preProcessIndex to use format from config #6845

Merged
merged 5 commits into from
Oct 10, 2022
Merged

Update Date.php preProcessIndex to use format from config #6845

merged 5 commits into from
Oct 10, 2022

Conversation

granitibrahimi
Copy link
Contributor

@granitibrahimi granitibrahimi commented Oct 7, 2022

When a format is specified for a Date field and the field is present on the list, it always throw a DateTime::__construct(): Failed to parse time string exception. Example I have created a date field with the format: "y-m" and when I add that field to the list then this is the thrown exception:

Could not parse '20-10': DateTime::__construct(): Failed to parse time string (20-10) at position 0 (2): Unexpected character {"userId":2,"exception":"[object] (Carbon\\Exceptions\\InvalidFormatException(code: 0): Could not parse '20-10': DateTime::__construct(): Failed to parse time string (20-10) at position 0 (2): Unexpected character at /var/www/html/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php:190) [stacktrace]
#0 /var/www/html/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php(216): Carbon\\Carbon::rawParse('20-10', NULL)
#1 /var/www/html/vendor/statamic/cms/src/Fieldtypes/Date.php(300): Carbon\\Carbon::parse('20-10')
#2 /var/www/html/vendor/statamic/cms/src/Fieldtypes/Date.php(126): Statamic\\Fieldtypes\\Date->parseSaved('20-10')
#3 /var/www/html/vendor/statamic/cms/src/Fieldtypes/Date.php(110): Statamic\\Fieldtypes\\Date->preProcessSingle('20-10')
#4 /var/www/html/vendor/statamic/cms/src/Fields/Field.php(314): Statamic\\Fieldtypes\\Date->preProcess('20-10')
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php(60): Statamic\\Fields\\Field->preProcess()
#6 [internal function]: Illuminate\\Support\\HigherOrderCollectionProxy->Illuminate\\Support\\{closure}(Object(Statamic\\Fields\\Field), 'date

When a format is specified for a Date field and the field is present on the list, it always throw a DateTime::__construct(): Failed to parse time string exception. Example I have created a date field with the format: "y-m" and when I add that field to the list then this is the thrown exception:

Could not parse '20-10': DateTime::__construct(): Failed to parse time string (20-10) at position 0 (2): Unexpected character {"userId":2,"exception":"[object] (Carbon\\Exceptions\\InvalidFormatException(code: 0): Could not parse '20-10': DateTime::__construct(): Failed to parse time string (20-10) at position 0 (2): Unexpected character at /var/www/html/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php:190) [stacktrace]
#0 /var/www/html/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php(216): Carbon\\Carbon::rawParse('20-10', NULL)
#1 /var/www/html/vendor/statamic/cms/src/Fieldtypes/Date.php(300): Carbon\\Carbon::parse('20-10')
#2 /var/www/html/vendor/statamic/cms/src/Fieldtypes/Date.php(126): Statamic\\Fieldtypes\\Date->parseSaved('20-10')
#3 /var/www/html/vendor/statamic/cms/src/Fieldtypes/Date.php(110): Statamic\\Fieldtypes\\Date->preProcessSingle('20-10')
#4 /var/www/html/vendor/statamic/cms/src/Fields/Field.php(314): Statamic\\Fieldtypes\\Date->preProcess('20-10')
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php(60): Statamic\\Fields\\Field->preProcess()
#6 [internal function]: Illuminate\\Support\\HigherOrderCollectionProxy->Illuminate\\Support\\{closure}(Object(Statamic\\Fields\\Field), 'date
@edalzell
Copy link
Contributor

edalzell commented Oct 7, 2022

Thanks for this @granitibrahimi can you please fix the style issues found by StyleCI?

@granitibrahimi
Copy link
Contributor Author

granitibrahimi commented Oct 7, 2022

Thanks for this @granitibrahimi can you please fix the style issues found by StyleCI?

Hey @edalzell just did it, and please squash the commits since obviously I messed them up lol

Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find. I've just pushed up a change to use an existing method that already exists for this purpose.

Thanks!

@jasonvarga jasonvarga merged commit bb2831a into statamic:3.3 Oct 10, 2022
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

Successfully merging this pull request may close these issues.

3 participants