Future posts and past posts

I’m developing a website with events on it and I’d like on this page to distinguish between past events and future events.
To semplify it, I’m setting the post “date:” to the event date as you can see in the posts
I’d like to split between “future events/posts” and past events where the present is the website build (it will be updated soon after each event with the event report).
I’ve seen that is possible to know the build date with {{ .Now }} and that is possible to put a where but it seems to be impossible to use the where for “>” and “<” but only for equalities. How can I overcome this?

 {{ range where .Data.Pages "Date.Unix" "<" .Now.Unix }}

Thanks a Lot :):):slight_smile:


But it would maybe be a natural improvement to be able to use time.Time directly in the where clause. /cc @tatsushid

@bjornerik, I’ll check it and will fix.

1 Like

I sent a PR. This changes where behavior to convert time.Time values into int, compare them and return the result. To convert time.Time values, it uses time.Unix() internally. I think it’s enough to compare such values.

That PR is now merged.

With the pull request in this topic, is possible to distinguish between posts in future based on a date X days in the future?

Today is 14 Oct 2015. I’d like to show only posts in past and in the future up to 1 month (14 Nov 2015). Is possible to use something like this?

 {{ range where .Data.Pages "Date.Unix" "<" .Now.Unix "+1 Month" }}

Thanks a lot :).

PS: I’ve seen that this stuff is not present in the doc. Wouldn’t make sense to mention it?

The pull request doesn’t say anything about the above. But this should be fairly straight forward by using the add func.

Thanks for the reply!
What do you mean by “add func”?

The add template func. It is in the doc.

In case it helps someone, the .Now.Unix syntax doesn’t work anymore, but now.Unix does.