[Solved] Ordinal date filter doesn't work


#1

I’ve been trying the new ordinal date filter but I get this message when I try to run the code. In my case the following pops up. I’ve tried both filters on the docs and one I found on a blog, none of them work.

Liquid Exception: no implicit conversion of Integer into String in /_layouts/post.html

It creates output if I remove the quotes around ordinal but doesn’t actually produce an ordinal (no "nth, or “rd” etc).

My layout file:

---
layout: default
---
<article class="post-page">
  <span class="label">{{ page.category }}</span>
  <h1 id="postTitle">{{ page.title }}</h1>
  <aside>
    <span class="label">{{ page.category }}</span>
    <time datetime="{{ page.date | date_to_xmlschema }}">
      {{ page.date | date_to_long_string: "ordinal" }}
    </time>
    <span title="{{ page.content | number_of_words }} words">
      {{ page.content | number_of_words | divided_by: 300 }} minute read
    </span>
  </aside>
  <section class="post-contents">
  {{ content }}
  {% if page.modified %}
  <aside>
    Modified: {{ page.modified | date_to_rfc822 }}
  </aside>
  {% endif %}
  </section>
  {% include post-footer.html %}
</article>

#2

what version of Jekyll? are you using GH pages?

looks like this was added in 3.8 but GH pages is 3.73


#3

It is the latest, 3.8 at least. I’m also hosting the site through AWS not GH. No idea what the problem is.


#4

Maybe it’s a bug. I’ve personally never tried date_to_long_string filter, I’ve only used the US flavor of it on my personal site.

{{ page.date | date_to_long_string: 'ordinal', 'US' }}

#5

I haven’t had a chance to sit down at my PC yet, but once I do I will try the date_to_string versions. Also I noticed the templates on jekyll.rb use “page.time” instead of “page.date” which seems like a red flag of sorts.


#6

Stupid question but what does the output of {{ page.date }} look like? Maybe that’s not in ISO format and could be why the filter isn’t working as it’s in a format it’s not expecting.


#7

I don’t think it’s a stupid question, you might be onto something.

Output (example from a post after running jekyll build):

2017-02-16 00:00:00 -0700

#8

You sure you’re using the latest version of Jekyll? I just tried v3.8.3 and added this to a sample post:

{{ page.date }}
{{ page.date | date_to_long_string: "ordinal" }}
{{ page.date | date_to_long_string: 'ordinal', 'US' }}

And got these results:

2015-08-10 08:08:50 -0400
10th August 2015
August 10th, 2015

#9

Yep, it’s the lastest, I have a cronjob update the gems for me.

Figured it out, it was something pretty stupid. I had copied an ordinal plugin from the web into the _plugin folder. Removing the file completely fixed the issue.

Now I only wish we had an option to maybe put the ordinal part (the “nth”, “rd”, “nd”) into superscript.


#10

Not sure how well font-variant-numeric: ordinal is supported but might be an option to style the date.


#11

Thanks. I think that will work, I’ll check it out. The font I have doesn’t have “proper” superscript support outside of numbers, but it might be good enough.