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

Date Range Help not so URGENT anymore

Started by ryan pao 8 years ago · 6 replies · 890 views
8 years ago

Hi all,
I was using dateRange in page collection like such:

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

this was working fine till May 31.

TXT
An exception has been thrown during the rendering of a template ("DateTime::__construct(): Failed to parse time string (20180532) at position 7 (2): Unexpected character").

I have tried

TWIG
d|date_modify("+1 day")|date('Ymd')
which yields: 19700822 the start of the UNIX time.
and with
"d"|date_modify("+1 day")|date('Ymd') ---> quoted the d variable
and this only returns 20180531 

with the results above I cannot iterate thorough the dates.
any pointers?

I have to present the site in a few days YIKES!

any insight appreciated !!!

8 years ago

Can you give us some context for the variable d? Where does it come from and what format is it?

Did you run an update on Grav core or any plugins on the 31st? If so, you might find clues (and bugs!) by looking through the changelogs.

Also, what is the result of {{ dump(d+1) }} and {{ dump(page.collection.dateRange(d, d+1)) }} just before your for loop? What if you hardcode some date values as dateRange parameters? Do you get the expected result?

8 years ago

Hi Hughbris,

Pardon me, I didn't explain enough.

abstract:
I'm am gathering all the page header dates and grouping the articles by their submission dates by:

  1. create array by

    TWIG
    {% set uDate=[] %}
    {% for i in page.collection %}
    {% set uDate = uDate|merge([i.date|date('Ymd')]) %}
    {% endfor %}
    {%- set uDate = uDate|array_unique  -%}
    

    trying to get unique YYYYmmdd values to iterate over.

  2. d to iterate over to group by submission dates.

    TWIG
    {%- for d in uDate -%}
    {% for post in page.collection.dateRange(d,d+1).order('date', 'desc') %}  {# working until 20180530 #}
    rendering process for pages collected by dateRange.
    
    {% endfor %}
    {% endfor %}
    
    • I'm willing to rewrite the code for 1. if there is another option to produce unique date values.
    • I'm going to wait a couple hours for the date to change (June 1) to give the original code another try.
    • here is the error dump:
      TXT
      An exception has been thrown during the rendering of a template ("DateTime::__construct(): Failed to parse time string (20180532) at position 7 (2): Unexpected character").
      

Thanks for your support !!

8 years ago

P.S.
current grav version: Current v1.4.4
I haven't updated or added anything else.

I'm going to erase all gathered pages and see what will happen.

8 years ago

Culprit Found !!

It wasn't the dateRange(d,d+1) 's fault.

it was "page.collection" returning (20180532).

I have to find a cleaner solution for this but, I will
touch -d the files that was created on 20180531.

Problem solved for now!.

8 years ago

Now you got me curious 😛

Why was page.collection returning 20180532? Do you mean d?

Why do you think this worked before May 31st?

Not urgent to reply, just wondering.

8 years ago

it wasn't the d's fault at all.

From what I've found was that a directory ..../user/pages/article/xxxx
was made on May 31 was returning returning (20180532).

and the error was triggered by

TXT
-> for i in page.collection
or
-> page.collection.dateRange

reverting my code to the original state. (one with the dateRange(d,d+1))
started working again when I

touch -d "20180601" …/user/pages/article/xxxx

I do not now why May 32nd happened, but let me update, as soon as I get to the bottom of this.
it may derive from locale. since I'm working in japan now.

and the time it happened was 0:00:00 GMT approx.

last edited 06/01/18 by ryan pao

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 74 6 hours ago
General · by pamtbaau, 11 hours ago
1 47 11 hours ago
General · by Andy Miller, 23 hours ago
0 43 23 hours ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 39 5 days ago