[SOLVED] Article expiration by date

I’m tempted to think this may be a bug, but it’s more likely something that I just don’t understand.

Given a section for events with these files:

event-1.md

+++
start = "2014-02-22T17:08:12-05:00"
expiration = "2014-02-22T17:08:12-05:00"
+++

event-2.md

+++
start = "2016-10-29T09:00:00+00:00"
expiration = "2016-10-29T09:00:00+00:00"
+++

event-3.md

+++
start = "2015-10-03T08:00:00-05:00"
expiration = "2015-10-03T08:00:00-05:00"
+++

and a range function like this:

{{ range  where .Data.Pages "Section" "event" }}
     {{ if ge $.Params.expiration.Unix .Now.Unix }}
            ...
    {{ end }}
{{ end }}

Absolutely nothing prints.
If I change the operator to “le” everything prints. My expectation is that event-2.md would print, but that’s not what happens.

This behavior does occur even if I use the exact code from the docs: https://gohugo.io/templates/go-templates/

Any ideas why?

You must use proper dates. See the TOML doc.

According to the spec we can use one of three datetime formats:

date1 = 1979-05-27T07:32:00Z
date2 = 1979-05-27T00:32:00-07:00
date3 = 1979-05-27T00:32:00.999999-07:00

mine are like this:

start = "2015-10-03T08:00:00-05:00"

What am I missing? Should I be omitting the quotation marks?

Yes. As I said, it is in the spec.

A couple of noteworthy things:

removing the quotation marks throws an error unless this format and only this format is used:
1979-05-27T07:32:00Z

Here’s the error - I tried both date formats two and three:

ERROR: 2016/07/28 Error parsing page meta data for event/2015-09-08-adopt-a-street.md
ERROR: 2016/07/28 Near line 7 (last key parsed 'date'): Expected 'Z' in ISO8601 datetime, but found '-' instead.
ERROR: 2016/07/28 Near line 11 (last key parsed 'dateeventstart'): Expected 'Z' in ISO8601 datetime, but found '.' instead.

It probably doesn’t make much difference and I don’t think it’s relevant to this problem, but not allowing for datetime options 2 and 3 means timezones can’t be accounted for in that scenario. screenshot: https://cl.ly/2q3j2w0y170F


Lastly. I changed the event dates to the format param = 2016-10-29T09:00:00Z and articles with dates greater than .Now are still not showing. If I change the code to less than equal to (le), then they all show up in the list. I purposefully have some articles with old dates and some with future dates as a test. screenshot: https://cl.ly/1E0Y0V0o2E1w

Yes there are some date issues with the TOML librafy in use:

There is also a discussion about switching it for a more modern one, @spf13 may know more.

Okay, now I feel smart. I didn’t define the params in the config. I’m going to mark this as solved and edit the name so others might avoid the mistake. :wink: