Translating a short bit of Ruby code (get next Saturday's date) into Liquid?

Solved
Highlighted
Tourist
26 0 1

Hello,

I recently found a bit of Ruby which creates a function to output the date of next Saturday (or whatever day you feed it):

require 'date'

def date_of_next()
  date  = Date.parse("Saturday")
  delta = date > Date.today ? 0 : 7
  date + delta
end

As you can see, it's super-compact. Would it be an easy task to translate this into Liquid? (I'd have thought it's possible, seeing as Liquid is apparently based on Ruby - or am I wrong? I'm very new to this!)

0 Likes
Highlighted
Shopify Partner
1806 211 374

This is an accepted solution.

Liquid engine is indeed running on Ruby, but you can't use any Ruby code directly in the Liquid. I would suggest you to move these bits onto a client side and use JavaScript instead of liquid.

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes