Failed date comparison

I am trying to filter in a collection of events the ones that have a date in the future ( > site.time ).
This works perfectly when it is the date of the post, but can’t make it work with an additional date from the YAML frontmatter.

In this case, I have an additional ‘end-date’ in some of the events, but that does not seem treated correctly in the where_exp filter:

{% assign filtered_events = | where_exp: 'event', ' >= site.time or event.end-date !="" and event.end-date >= site.time' %}

results in this error:

/home/bibliotecaris/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/liquid-4.0.3/lib/liquid/condition.rb:127:in `rescue in interpret_condition': Liquid error (line 37): comparison of Date with Time failed (Liquid::ArgumentError)

In the front-matter it is some times:

date: 2022-03-15
end-date: 2022-05-31

and some other:

date: 2022-03-15
end-date: ""

Any ideas?
Thanks a lot in advance! :slight_smile:


Well this is the current workaround I am using, if it can be useful for others.

I created a plugin to simply make a Date out of a Time…

require 'liquid'

module ToDate
  def to_date(time)

    # We want the date to be in the default Jekyll format: YYYY-MM-DD HH:MM:SS +/-TTTT, but all we need is the YYYY-MM-DD part
    date = Date.parse(time.to_s)
    return date

and then in the layout I just make a date object to compare to the one in the frontmatter.

 {% assign site_date = site.time | to_date %}

If there is simpler ways or I am doing something wrong, absurd let me know! :slight_smile:


You were probably right in doing what you did. Working with dates in Jekyll can be very frustrating. This is the documentation for the date filter that Liquid uses if that helps: