Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dateRange without end date problem #898

Closed
Sogl opened this issue Jun 14, 2016 · 10 comments
Closed

dateRange without end date problem #898

Sogl opened this issue Jun 14, 2016 · 10 comments

Comments

@Sogl
Copy link
Contributor

Sogl commented Jun 14, 2016

Hello!

This issue related to:
#274
#275

I'm trying to show some posts from blog to in a home modular page depending to start date and found a bug with dateRange filter. Blog has 2 posts with 2013 and 2016 years.

My section frontmatter.yaml:

events:
    items:
        '@page': '/events'
    dateRange:
        start: 1/1/2012
        end: 1/1/2017

Markdown:

{% set events_collection = page.collection('events') %}

{% for event in events_collection %}
    <p>{{ event.title }}</p>
{% endfor %}

With this settings I see both posts, it's fine.

But without end date in frontmatter.yaml:

events:
    items:
        '@page': '/events'
    dateRange:
        start: 1/1/2012

I see no posts at all.

Env:

  • Grav v1.1.0-rc.1
@flaviocopes
Copy link
Contributor

Mmm I tried but I can't replicate, it works fine to me.

@Sogl
Copy link
Contributor Author

Sogl commented Jun 14, 2016

It replicates also with field: header.date.

How to see full request to my /events?

@flaviocopes
Copy link
Contributor

What's an example of a child page? Do you define the date there?

@Sogl
Copy link
Contributor Author

Sogl commented Jun 14, 2016

What's an example of a child page? Do you define the date there?

title: Post with a Background Image
date: 25.10.2013

I don't know what happened, but it's working on my home Mac machine after git pull 😕
Cache is always disabled.

Need to check on Windows machine where it happen.

@rhukster
Copy link
Member

Please check the Grav version specifically, see if they are in sync.

@flaviocopes
Copy link
Contributor

Yep I also got it working by using the format of the child page you use (setting the date manually)

@Sogl
Copy link
Contributor Author

Sogl commented Jun 14, 2016

Please check the Grav version specifically, see if they are in sync.

Versions are equal. I'm using one git repo with full site copy.

Hah... it reproduces on my Windows machine in the same way. No matter what date format is setting in post.

p.s. Just updated to Grav v1.1.0-rc.2 without no effect to this issue.

@Sogl
Copy link
Contributor Author

Sogl commented Jun 14, 2016

I think I found a spot where problem starts:
https://github.com/getgrav/grav/blob/develop/system/src/Grav/Common/Page/Collection.php#L273

Setting end: now +21 years is working, but end: now +22 years is not.

$date = date('d-m-Y', strtotime('now +21 years'));
echo $date . "<br>"; //15-06-2037
$date = date('d-m-Y', strtotime('now +22 years'));
echo $date; //01-01-1970

Specifications:
https://secure.php.net/manual/en/function.strtotime.php#refsect1-function.strtotime-notes

Strange, because I'm using PHP 5.6 x64.

Sogl pushed a commit to Sogl/grav that referenced this issue Jun 15, 2016
Related to getgrav#898

I can't find better way to remove it with DRY principle 😑
With smaller code we need to check a value for each `$this->items` iteration.

Also it can be used with `PHP_INT_MAX` with previous version of this code.
@flaviocopes
Copy link
Contributor

Ok so this problem is specific to 32-bit systems, where the dates end on 2038-01-19 03:14:07, and 22 years point us over that date - would have never thought about that.

Testing the PR

flaviocopes pushed a commit that referenced this issue Jun 15, 2016
* Remove end date check if not specified (better 32-bit support)

Related to #898

I can't find better way to remove it with DRY principle 😑
With smaller code we need to check a value for each `$this->items` iteration.

Also it can be used with `PHP_INT_MAX` with previous version of this code.

* Include endpoints
@flaviocopes
Copy link
Contributor

Merged PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants