Sommerregen / grav-theme-machine

This theme is a Grav port of the Machine HTML Template (http://w3layouts.com/machine-industrial-category-flat-bootstrap-responsive-web-template/) developed by W3Layouts (http://w3layouts.com/).
Other
7 stars 3 forks source link

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

Closed Lownin closed 7 years ago

Lownin commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

That worked. Thank you.

Sommerregen commented 7 years ago

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

webmastergta commented 6 years ago

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