/system/src/Grav/Common/Utils.php getting 20180732 as a date *july 32nd

hello, This problem was dormant for a while and I’ve completely ignored about the day31 issue
now that I’ve got better accustomed to the debugger, here is the out put of the phenomenon

here is the original problem:https://discourse.getgrav.org/t/date-range-help-not-so-urgent-anymore/6469

"DateTime::__construct(): Failed to parse time string (20180732) at position 7 (2): Unexpected character"

the system is passing 20180732 as a argument to

any way I can avoid crikey by touch -d xxxxxxx of a file to avoid post from the 31st.

any way to fix this?

Where is this non-date coming from? If it’s in a page’s frontmatter, then just change the page. If the filesystem itself is returning this date, then you have a much larger problem. That shouldn’t be possible. You’ll need to find forums for your OS. I don’t see how this is a Grav issue. It’s doing exactly what it’s supposed to do: blow up when given an invalid date.

hi Perlkonig, thanx for your reply.
The page collection is gathering post from the creation date of a file, so I’m speculating that daterange function being the culprit.

{% for post in page.collection.dateRange(d,d+1).order('date', 'desc') %}

Well here’s the code. There’s nothing there that sets any dates. It only selects pages that fall within the range.

Here’s the line that’s causing your problem. You’ll see it’s pulling the date from the date field of the page.

And here’s the code for the date function.

If you keep going down the rabbit hole, you see that the date comes from the page’s front matter or from the file system.

So there are two immediately obvious causes:

  1. The date in the front matter is invalid.
  2. Your file system is borked and is returning an invalid date (unlikely).

Can you post the front matter of the offending page?

hi Perlkonig,

Thank you for your assistance:

Your post totally makes sense to me now!

having past 4 days (from july 31st) the code seems to be working normally.

To prevent this from happening on the next 31st.
Ill be taking the route described below.

and here is the frontmatter:

title: this page is corrupt
topvisible: true
author: Ed Bickert
  1. I’ve not set a date input field for the post when created
  2. page collection was collecting the post from the date created
    hence touching -d provided the temporary solution.

to Fix the problem:

I’m creating the date field to go to the frontmatter header.
providing the base for the page collection to gather.

Arigato for your support !
Grav team rocks!!!

P.S. I’ll update on the fix as soon as the matter is fixed

The 32nd problem has been finally addressed.

here is the fix:

 1. get unique date from various posts by:
 {% set uDate=[] %}
    {% for i in page.collection %}
    {# {% set uDate = uDate|merge([i.date|date('Ymd')]) %} #}
 2. changed the format so it would be recognized as a date.
    {% set uDate = uDate|merge([i.date|date('Y-m-d')]) %} 
    {% endfor %}
    {%- set uDate = uDate|array_unique  -%}

 3. set the range terminator variable by date_modify  no more day 32!!
   {% set e = d|date_modify("+1 day")|date("Y-m-d") %}

finally use 
       {% for post in page.collection.dateRange(d,e).order('date', 'desc') %}

Thanking all for your inputs!

1 Like