Date Range Help not so URGENT anymore

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

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

this was working fine till May 31.

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

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 !!!

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?

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
 {% 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.

  1. d to iterate over to group by submission dates.
{%- 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:
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 !!

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.

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!.

Now you got me curious :stuck_out_tongue:

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.

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

-> 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.