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::__construct(): Failed to parse time string (06-23-2014) at position 0 (0): Unexpected character" #2

Closed
Lownin opened this issue Feb 3, 2017 · 4 comments

Comments

@Lownin
Copy link

Lownin commented Feb 3, 2017

Getting this error when attempting to use grav-theme-machine on fresh grav install.

"DateTime::__construct(): Failed to parse time string (06-23-2014) at position 0 (0): Unexpected character"

Highlights line 581 of system/src/Grav/Common/Utils.php

I'm running under MAMP on macOS.

screen shot 2017-02-02 at 5 19 43 pm

@Sommerregen
Copy link
Owner

Sommerregen commented Feb 4, 2017

Hi @Lownin,

I presume you are using the demo content right? As you can see the date error is coming from the file blog_post.md file. I could recreate the error. At the time the demo content, Grav only supported a limited number of formats like m-d-Y. Now it can use any formats.

You have two possibilities now. Either you change the date in the above file to, e.g., date: '2014-06-23' or you can add the default format pages.dateformat.default: 'm-d-Y' into your system.yaml.

Sommerregen


For myself I add some code to recreate the problem in pure PHP.

// The "right" way defining default datetimes
$datetime = new DateTime('2014-06-23');

// A Hack using pages.dateformat.default: 'm-d-Y'`
$datetime = DateTime::createFromFormat('m-d-Y', '06-23-2014');

@Lownin
Copy link
Author

Lownin commented Feb 4, 2017

That worked. Thank you.

@Sommerregen
Copy link
Owner

FYI: I just updated the theme and corrected the demo content. Thanks 👍

@webmastergta
Copy link

yetiforce
Error!!! DateTime::__construct(): Failed to parse time string (04-2018-10 08:00:00) at position 0 (0): Unexpected character

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants