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?
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?
abstract:
I’m am gathering all the page header dates and grouping the articles by their submission dates by:
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.
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").
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.