Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

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

Started by ryan pao 8 years ago · 5 replies · 522 views
8 years ago

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:/forum/general/date-range-help-not-so-urgent-anymore-t2407

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

the system is passing 20180732 as a argument to
/system/src/Grav/Common/Utils.php

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

any way to fix this?

8 years ago

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.

8 years ago

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.

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

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?

8 years ago

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:

YAML
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

8 years ago

The 32nd problem has been finally addressed.

here is the fix:

TWIG
 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
last edited 08/10/18 by ryan pao

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 76 8 hours ago
General · by pamtbaau, 13 hours ago
1 47 12 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago