Added locale date and ordinalize support for special words

Necessary to match link:https://shopify.github.io/liquid/filters/date[Liquid Date] behavior where you can use special words (i.e. "now" or "today") to equate to `Time.now`.

The specs use regular expressions because we are dealing with relative dates which would cause build failures if using exact string matches.

Milestone: minor
This commit is contained in:
Brooke Kuhlmann
2026-02-04 14:39:36 -07:00
parent 4db5febbb3
commit a91dec61e5
2 changed files with 21 additions and 0 deletions
+1
View File
@@ -151,6 +151,7 @@ module TRMNL
def to_time value
case value
when "now", "today" then Time.now
when Integer then Time.at(value)
else Time.parse value
end
+20
View File
@@ -171,6 +171,16 @@ RSpec.describe TRMNL::Liquid::Filters do
end
describe "#l_date" do
it "answers now as date/time" do
content = renderer.call %({{ "now" | l_date: "%Y-%m-%d" }}), {}
expect(content).to match(/\d{4}-\d{2}-\d{2}/)
end
it "answers today as date/time" do
content = renderer.call %({{ "today" | l_date: "%Y-%m-%d" }}), {}
expect(content).to match(/\d{4}-\d{2}-\d{2}/)
end
it "answers UNIX timestamp as date/time" do
content = renderer.call %({{ 1770134949 | l_date: "%Y %b" }}), {}
expect(content).to eq("2026 Feb")
@@ -297,6 +307,16 @@ RSpec.describe TRMNL::Liquid::Filters do
end
describe "#ordinalize" do
it "answers now as date/time" do
content = renderer.call %({{ "now" | ordinalize: "%B <<ordinal_day>>" }}), {}
expect(content).to match(/[a-zA-Z]+ \d+[a-z]{2}/)
end
it "answers today as date/time" do
content = renderer.call %({{ "today" | ordinalize: "%B <<ordinal_day>>" }}), {}
expect(content).to match(/[a-zA-Z]+ \d+[a-z]{2}/)
end
it "answers UNIX timestamp as date/time" do
content = renderer.call %({{ 1770134949 | ordinalize: "%A, %B <<ordinal_day>>, %Y" }}), {}
expect(content).to eq("Tuesday, February 3rd, 2026")