Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Updated {{ 'now' | date :'%Y' }} to work with Ruby 1.9.3 #117

Merged
merged 2 commits into from

7 participants

@ndwebgroup

...e :'%Y' }} work.

In the case of Ruby 1.9.3, 'now' is no longer parsed. For safe
measures, I've added 'today' as well.

jeremyf added some commits
@jeremyf jeremyf Added tests to verify that {{ 'now' | date :'%Y' }} and {{ 'today' | …
…date :'%Y' }} work.

In the case of Ruby 1.9.3, 'now' is no longer parsed.  For safe
measures, I've added 'today' as well.
5d0004a
@jeremyf jeremyf Merge branch 'master' of git://github.com/Shopify/liquid
* 'master' of git://github.com/Shopify/liquid:
  * Seperated 'Howto' into 'How to'. * Added periods to the second list as the first item has them. I guess I'm anally retentive like that. :)
  Fix conditions using negative number comparisons
740cd6e
@dekellum

I just was bitten by this as well. Any update? Ruby 1.9.3 or Liquid bug?

@CraigCottingham

I just ran into this as well. Since there doesn't seem to be any progress with accepting this pull request, I worked around it by using {{ site.time | date: '%y' }}. Note that I'm using Jekyll, so maybe this won't work outside of that.

@aprescott

Is there any update with this?

@aprescott aprescott referenced this pull request in aprescott/serif
Closed

Document available variables / tags / filters #26

@fw42
Owner

Seems to be a Ruby 1.9.3 regression. Looks good to me. No apparent performance impact. @boourns?

@fw42 fw42 commented on the diff
lib/liquid/standardfilters.rb
@@ -169,7 +169,16 @@ def date(input, format)
input = Time.at(input.to_i)
end
- date = input.is_a?(String) ? Time.parse(input) : input
+ date =
+ if input.is_a?(String)
@fw42 Owner
fw42 added a note

This indentation is weird. Can we fix that? (move the if up into the date = ... line)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@boourns
Owner

:shipit:

@fw42 fw42 commented on the diff
lib/liquid/standardfilters.rb
@@ -169,7 +169,16 @@ def date(input, format)
input = Time.at(input.to_i)
end
- date = input.is_a?(String) ? Time.parse(input) : input
+ date =
+ if input.is_a?(String)
+ case input.downcase
+ when 'now', 'today' then Time.now
@fw42 Owner
fw42 added a note

Nitpicking, can we move the Time.now into the next line and drop the then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fw42
Owner

@ndwebgroup, if you could fix my two little comments, I will merge this. Thanks for contributing!

@fw42 fw42 was assigned
@fw42 fw42 merged commit 740cd6e into Shopify:master
@fw42
Owner

Merged in 8ca4868

@SonicHedgehog SonicHedgehog referenced this pull request in coffeescript-cookbook/coffeescript-cookbook.github.io
Merged

Automatically update “last updated” date #92

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 19, 2012
  1. @jeremyf

    Added tests to verify that {{ 'now' | date :'%Y' }} and {{ 'today' | …

    jeremyf authored
    …date :'%Y' }} work.
    
    In the case of Ruby 1.9.3, 'now' is no longer parsed.  For safe
    measures, I've added 'today' as well.
  2. @jeremyf

    Merge branch 'master' of git://github.com/Shopify/liquid

    jeremyf authored
    * 'master' of git://github.com/Shopify/liquid:
      * Seperated 'Howto' into 'How to'. * Added periods to the second list as the first item has them. I guess I'm anally retentive like that. :)
      Fix conditions using negative number comparisons
This page is out of date. Refresh to see the latest.
View
11 lib/liquid/standardfilters.rb
@@ -169,7 +169,16 @@ def date(input, format)
input = Time.at(input.to_i)
end
- date = input.is_a?(String) ? Time.parse(input) : input
+ date =
+ if input.is_a?(String)
@fw42 Owner
fw42 added a note

This indentation is weird. Can we fix that? (move the if up into the date = ... line)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ case input.downcase
+ when 'now', 'today' then Time.now
@fw42 Owner
fw42 added a note

Nitpicking, can we move the Time.now into the next line and drop the then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ else
+ Time.parse(input)
+ end
+ else
+ input
+ end
if date.respond_to?(:strftime)
date.strftime(format.to_s)
View
2  test/liquid/standard_filter_test.rb
@@ -103,6 +103,8 @@ def test_date
assert_equal '07/05/2006', @filters.date("2006-07-05 10:00:00", "%m/%d/%Y")
assert_equal "07/16/2004", @filters.date("Fri Jul 16 01:00:00 2004", "%m/%d/%Y")
+ assert_equal "#{Date.today.year}", @filters.date('now', '%Y')
+ assert_equal "#{Date.today.year}", @filters.date('today', '%Y')
assert_equal nil, @filters.date(nil, "%B")
Something went wrong with that request. Please try again.